请求数据时给请求头加上token值(全局加)
在main.js中加上以下代码
// 添加请求拦截器
axios.interceptors.request.use(config => {
// 在发送请求之前做些什么
//判断是否存在token,如果存在将每个页面header都添加token
//if中的值为登陆时存入vuex中的token值
//如果存在token值,将token放入请求头‘Authorization’中
if(store.state.token.token){
config.headers.common['Authorization']=store.state.token.token
}
return config;
}, error => {
// 对请求错误做些什么
return Promise.reject(error);
});

浙公网安备 33010602011771号