// http request 拦截器 axios.interceptors.request.use( config => {
var token = localStorage.getItem("antToken"); //检查是否有token,有的话说明是已登录,没有就说明未登录
if (token) { //如果登录了就在每个接口的headers里面增加token
config.headers.token = token;
} return config; }, err => { return Promise.reject(err); });
axios.interceptors.response.use( response => { if(response.data.errorCode === "2001") { alert(‘123‘) return; } return response; }); error => { if (error.response) { switch (error.response.status) { case 111: alert(‘123‘) } } // console.log(JSON.stringify(error));//console : Error: Request failed with status code 402 return Promise.reject(error.response.data) // 返回接口返回的错误信息 });