迪奧生物做圖網(wǎng)站寧波seo優(yōu)化公司排名
零碎語法
1.導(dǎo)入某個文件夾的index文件,index可以省略(這里導(dǎo)入的是router和store文件下的index.js文件)
2.路由懶加載
this
1.在vue文件中使用router\store對象時
this:普通函數(shù)的this指向vue實例對象(在沒有明確指向的時候this指向window)
router和store掛載在vue上之后
在模板中使用 router或store的方法為 $router.xxx或$store.xxx
在方法中調(diào)用方式為:this.$router.xx或this.$store.xxx
2.在js文件中使用router\store對象時
使用什么需要導(dǎo)入時候,掛載在vue全局對象上的對象在vue文件中可以使用,在js文件中不能使用
網(wǎng)絡(luò)通信
axios功能拆分寫法
還可以配置攔截器
import axios from 'axios'// 下面是克隆一份新的axios
const request = axios.create({baseURL: 'http://interview-api-t.itheima.net',timeout: 5000
})
// 添加請求攔截器
axios.interceptors.request.use(function (config) {// 在發(fā)送請求之前做些什么// 在發(fā)送請求之前做些什么// config === https://www.axios-http.cn/docs/req_config === 請求的配置對象const token = localStorage.getItem('mobile-token')config.headers.Authorization = `Bearer ${token}`return config
}, function (error) {// 對請求錯誤做些什么return Promise.reject(error)
})export default request
css預(yù)處理(Sass\Stylus\Less\Scss)
參考
token
將token存儲到vuex中比存儲到本地更快,但是只要頁面一刷新token就失效,想要永久存儲還是需要在本地存儲中存儲一份token
//舉例(只在頁面刷新的時候用到了本地存儲,添加請求頭用的token是從vuex中取,不用在從本地存儲中取
export default {namespaced: true,state: {token: localStorage.getItem('mj-pc-token')},mutations: {updateToken (state, newToken) {state.token = newTokenlocalStorage.setItem('mj-pc-token', newToken)}},actions: {}
}