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('需要重新登录');
    }
  })
  
相关推荐
大数据魔法师44 分钟前
Bootstrap项目 - 个人作品与成就展示网站
前端·bootstrap·html
He_k3 小时前
‘js@https://registry.npmmirror.com/JS/-/JS-0.1.0.tgz‘ is not in this registry
开发语言·javascript·ecmascript
LaughingZhu4 小时前
PH热榜 | 2025-05-29
前端·人工智能·经验分享·搜索引擎·产品运营
汪子熙6 小时前
Angular i18n 资源加载利器解析: i18n-http-backend
前端·javascript·面试
天天扭码6 小时前
在React项目中实现富文本编辑文章并发布
前端·react.js·github
Yehong6 小时前
nuxt实现50个前端小创意(1)——前端基础学习
前端·vue.js
拉不动的猪6 小时前
回顾vue3组件在运行过程中的编译提升
前端·vue.js·trae
天天扭码6 小时前
前端必备 | 一文掌握React的Token管理
前端·javascript·react.js
烛阴6 小时前
用Joi守住数据防线!Node.js/前端必备校验神器入门与进阶
前端·javascript
神秘敲码人7 小时前
前端面试题-HTML篇
前端·面试·html