參考:https://www.cnblogs.com/feijiediyimei/p/9940937.html
因為使用了jwt鑒權,需要每次請求的時候帶上token。
在main.js中加入axios的全局攔截器可解。
// 添加一個請求攔截器
axios.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
//這里經常搭配token使用,將token值配置到tokenkey中,將tokenkey放在請求頭中
config.headers['Authorization'] = token;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
// 添加一個響應攔截器
axios.interceptors.response.use(function (response) {
// Do something with response data
return response;
}, function (error) {
// Do something with response error
return Promise.reject(error);
});