vue2拦截器 拦截后端返回的数据,并判断是否需要登录
axios.interceptors.response.use(res => {
// 添加响应数据日志
console.log('接口返回数据:', {
url: res.config.url,
method: res.config.method,
response: res.data
});
// 检查是否返回登录页面HTML
if (typeof res.data === 'string' && res.data.includes('<!DOCTYPE html>') && res.data.includes(登录系统')) {
console.log('检测到返回登录页面,准备跳转...');
//删除 过期 token
MessageBox.alert('登录已过期,请重新登录', {
confirmButtonText: '跳转登录页面',
callback: action => {
window.location.href = Url+'/login‘
}
});
return Promise.reject('需要重新登录');
}
})