// 数据响应拦截器,统一处理返回的数据逻辑
axios.interceptors.response.use(res => {
if (res && res.status == HTTP_STATUS.SUCCESS) {
return res.data;
} else {
ToastToTxt(window.rootVue, '网络异常');
}
}, error => {
let e = {
message: '服务器未知错误'
}
if (error.response && error.response.data) {
e = {
message: error.response.data
}
}
// 授权过期
if (e.code === 401) {
e.message = '授权过期'
}
return Promise.reject(e);
})
标签:拦截器,res,message,Vue,error,思路,data,response
From: https://www.cnblogs.com/IT-IOS-MAN/p/16891674.html