vue2拦截器 拦截后端返回的数据,并判断是否需要登录

vue2拦截器 拦截后端返回的数据,并判断是否需要登录

vue 复制代码
  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('需要重新登录');
    }
  })
  
相关推荐
ruanCat1 小时前
Prettier 明明执行成功,Markdown 为什么还是没变?一次插件误诊复盘
前端·javascript·node.js
软件开发技术深度爱好者1 小时前
在线学习实践 TypeScript 的官方Playground(演练场)使用介绍
javascript·学习·typescript