建設(shè)工程招標(biāo)網(wǎng)站互聯(lián)網(wǎng)推廣運(yùn)營(yíng)是做什么的
目錄
前言
一、Axios基礎(chǔ)認(rèn)識(shí)
1、簡(jiǎn)介
2、相關(guān)文檔
3、基本配置
4、基礎(chǔ)快捷使用
二、Axios封裝
1、公共配置文件
2、細(xì)化每個(gè)接口的配置
3、使用并發(fā)送請(qǐng)求
三、SASS
1、簡(jiǎn)介
2、相關(guān)文檔
3、使用前奏
4、使用變量
5、嵌套規(guī)則
6、父級(jí)選擇器標(biāo)識(shí) &
前言
1、打包工程各個(gè)頁(yè)面的統(tǒng)一命名
component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
注意:/* webpackChunkName: "about" */不是注釋,作用:打包工程時(shí)文件的命名開(kāi)頭統(tǒng)一
2、網(wǎng)頁(yè)地址時(shí)有時(shí)無(wú)的 #
const router = new VueRouter({mode: "history",//控制網(wǎng)址是否有#,設(shè)置了就沒(méi)有#base: process.env.BASE_URL,routes,
});
一、Axios基礎(chǔ)認(rèn)識(shí)
1、簡(jiǎn)介
Axios 是一個(gè)基于 promise?網(wǎng)絡(luò)請(qǐng)求庫(kù),作用于 node.js 和瀏覽器中
它是 isomorphic (同構(gòu))的,即同一套代碼可以運(yùn)行在瀏覽器和 node.js 中
在服務(wù)端它使用原生 node.js http 模塊,而在客戶端 (瀏覽端) 則使用 XMLHttpRequests
2、相關(guān)文檔
(1)Axios官方文檔
起步 |?Axios中文文檔 | Axios中文網(wǎng)https://www.axios-http.cn/docs/intro(2)現(xiàn)代 JavaScript 教程之Promise
Promisehttps://zh.javascript.info/promise-basics
3、基本配置
(1)安裝
npm install axios
(2)引入:在main.js文件中引入
// 使用CommonJS規(guī)范
const axios = require('axios').default;
// 使用Es6規(guī)范
import axios from 'axios'
4、基礎(chǔ)快捷使用
(1)未帶請(qǐng)求參數(shù)
/* GET請(qǐng)求 */
axios.get('url',{}).then((res)=>{//成功console.log(res)}).catch((err)=>{console.log(err)})/* POST請(qǐng)求 */
axios.post("url", {username: "xxxxxx",password: "xxxxxx",
}).then((res) => {console.log(res);}).catch((err) => {console.log(err);});
(2)帶請(qǐng)求參數(shù)
注意:GET請(qǐng)求帶參使用params;POST請(qǐng)求帶參使用data
/* GET請(qǐng)求 */
axios({method:"GET",url:'',params:{key:'',},
}).then((res)=>{console.log(res)}).catch((err) => {console.log(err);});/* POST請(qǐng)求 */
axios({method:"POST",url:'',data:{key:'',},headers:{'content-type':'application/x-www-form-urlencoded',},
}).then((res)=>{console.log(res)}).catch((err) => {console.log(err);});
二、Axios封裝
1、公共配置文件
在src文件夾下=》創(chuàng)建request文件夾=》request.js文件
/* request.js */
// 引入axios
import axios from "axios";// 創(chuàng)建實(shí)例,并帶上默認(rèn)配置
const instance = axios.create({baseURL: "",// timeout 指定請(qǐng)求超時(shí)的毫秒數(shù)// 如果請(qǐng)求時(shí)間超過(guò) timeout 的值,則請(qǐng)求會(huì)被中斷timeout: 1000, // 默認(rèn)值是 0 (永不超時(shí))headers: {'X-Custom-Header': 'f3oobar'} // 默認(rèn)請(qǐng)求頭
});// 導(dǎo)出實(shí)例
export default instance;
2、細(xì)化每個(gè)接口的配置
在src文件夾下=》新建api文件夾=》新建js文件,如about.js、home.js、index.js...
/* /api/index.js */// 引入axios實(shí)例
import instance from '@/request/request.js'// 獲取用戶信息(GET請(qǐng)求)
export function userInfo(params){return instace({url:"/user",method:"GET",params//增強(qiáng)寫法})
}// 獲取用戶信息(POST請(qǐng)求)
export function userInfo(data){return instace({url:"/user",method:"POST",data,headers:{'content-type':'application/x-www-form-urlencoded'}})
}
3、使用并發(fā)送請(qǐng)求
到.vue頁(yè)面文件中,按需引入需要用的接口函數(shù)
<template>
<div>歡迎登錄系統(tǒng)。
</div>
</template>
<script>// 引入接口函數(shù)import { userInfo } form '@/api/index.js'export default{created(){this.getUserInfo()},method:{getUserInfo(){userInfo({ID:12345}).then(res=>{console.log(res)}).catch(err=>{console.error(err)})}}}
</script>
三、SASS
1、簡(jiǎn)介
Sass 是一款強(qiáng)化 CSS 的輔助工具
它在 CSS 語(yǔ)法的基礎(chǔ)上增加了變量 (variables)、嵌套 (nested rules)、混合 (mixins)、導(dǎo)入 (inline imports) 等高級(jí)功能
這些拓展令 CSS 更加強(qiáng)大與優(yōu)雅,以及更高效地開(kāi)發(fā)項(xiàng)目
2、相關(guān)文檔
Sass基礎(chǔ)教程 Sass快速入門 Sass中文手冊(cè) | Sass中文網(wǎng)Sass是世界上最成熟、穩(wěn)定和強(qiáng)大的專業(yè)級(jí)CSS擴(kuò)展語(yǔ)言https://www.sass.hk/guide/
3、使用前奏
(1)快速安裝
通過(guò)創(chuàng)建Vue腳手架時(shí),勾選【CSS Pre-processors】=>【Sass/SCSS (with dart-sass)】
(2)開(kāi)啟sass
在<style>
標(biāo)簽中,加上屬性配置:lang="scss"
<style lang="scss">
4、使用變量
(1)聲明變量
用 $ 聲明變量,用 : 賦值
$highlight-color: #F90;
(2)變量引用
用 $ 直接引用變量,sass會(huì)自動(dòng)解析
border: 1px solod $highlight-color;
(3)代碼示例
<template><div><h1>主頁(yè)</h1><p>1</p><p>1</p></div>
</template><style lang="scss" scoped>
$font-color: #F90;
$bg: #4662D9;h1 {color: $font-color;
}
p {color: $font-color;
}
</style>
5、嵌套規(guī)則
在sass中,可以像俄羅斯套娃那樣在規(guī)則塊中嵌套規(guī)則塊,嵌套關(guān)系即父子關(guān)系
sass
在輸出css
時(shí)會(huì)把這些嵌套規(guī)則處理好,避免重復(fù)書寫
注意:此嵌套關(guān)系并非嚴(yán)謹(jǐn)?shù)闹毕蹈缸雨P(guān)系,僅代表包含關(guān)系
<template><div><div class="card"><div class="header">頭部</div><div class="content">內(nèi)容<div class="header">內(nèi)容的頭部</div></div></div></div>
</template><style lang="scss" scoped>
// 變量
$font-color: #F90;
$bg: #4662D9;// 嵌套
.card {font-weight: bold;width: 600px;height: 300px;background-color: $font-color ;.header {height: 40px;background-color: $bg;}.content {height: 300px;background-color: yellow;.header {background-color: aqua;}}
}
</style>
6、父級(jí)選擇器標(biāo)識(shí) &
& 符號(hào)在每一層的選擇器中,標(biāo)識(shí)當(dāng)前選擇器自身,方便直接在聯(lián)級(jí)中書寫偽類等 css 屬性
<style lang="scss" scoped>.header {background-color: aqua;&:hover {background-color: red;}}
</style>