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('需要重新登录');
    }
  })
  
相关推荐
lichenyang45310 小时前
鸿蒙 ArkUI 组件基础复盘:从两个 UI 卡片回到 ComponentV2、状态管理和组件分层
前端
biubiubiu_LYQ10 小时前
萌新小白基础理解篇之 this 关键字
前端·javascript
甜味弥漫10 小时前
深度解析 JS 中的 this 指向:从底层逻辑到实战规则
javascript·面试
光影少年10 小时前
Redux 中间件作用(redux-thunk/redux-saga)
前端·react.js·掘金·金石计划
爱上好庆祝10 小时前
学习JS第十一天(JS的进阶)
前端·javascript·学习
喵个咪10 小时前
统一范式:中后台Admin项目标准化API分层开发方案(Vue/React通用)
前端·vue.js·react.js
Shirley~~10 小时前
figma Mcp
前端·ai编程
Bacon10 小时前
Gstack + Superpowers:当 AI 编程的"脑子"和"手脚"终于在一起了
前端·人工智能
喵个咪10 小时前
拒绝过度封装!GoWind Admin:基于Element Plus重塑中后台CRUD开发范式
前端·vue.js·typescript
Komorebi_999911 小时前
LangChain Day5 课程:Agent 智能代理
前端·langchain·大模型