axios发送请求未经过拦截器的疑问
axios在create或者mounted生命周期内使用post请求未经过拦截器拦截器axios.interceptors.request.use(config => {if (localStorage.ticket) {// 判断是否存在token,如果存在的话,则每个http header都加上tokenconsole.log('have');config.headers.ticket
·
axios在create或者mounted生命周期内使用post请求未经过拦截器
拦截器
axios.interceptors.request.use(
config => {
if (localStorage.ticket) { // 判断是否存在token,如果存在的话,则每个http header都加上token
console.log('have');
config.headers.ticket = `${localStorage.ticket}`;
}else {
console.log('no');
}
return config;
},
err => {
return Promise.reject(err);
});
mounted() {
this.getcarousel();
},
getcarousel:function(){
axios.post('/api/service/index/getindex',params,config).then(function (result) {
console.log('do');
if (result.data.success==false && result.data.msg=='tk'){
_this.$router.push('/login')
}
_this.carousel=result.data.msg
console.log(_this.carousel)
});
},

后端返回无token,并未进入拦截器
暂时使用单独添加token的方式解决,先放在这里,以后找到方案再来填坑
更多推荐


所有评论(0)