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('需要重新登录');
    }
  })
  
相关推荐
风度前端19 分钟前
用了都说好的 uniapp 路由框架
前端
冴羽20 分钟前
2026 年 Web 前端开发的 8 个趋势!
前端·javascript·vue.js
码银28 分钟前
ruoyi的前端(vue)新增的时候给字典设置默认值 但不能正常
前端
五仁火烧1 小时前
Vue3 项目的默认端口行为
服务器·vue.js·nginx·容器·vue
fengbizhe1 小时前
bootstrapTable转DataTables,并给有着tfoot的DataTables加滚动条
javascript·bootstrap
刘一说1 小时前
TypeScript 与 JavaScript:现代前端开发的双子星
javascript·ubuntu·typescript
凌览1 小时前
别再死磕 Nginx!http-proxy-middleware 低配置起飞
前端·后端
EndingCoder2 小时前
类的继承和多态
linux·运维·前端·javascript·ubuntu·typescript
用户47949283569152 小时前
React 终于出手了:彻底终结 useEffect 的"闭包陷阱"
前端·javascript·react.js
程序员猫哥2 小时前
前端开发,一句话生成网站
前端