vue 统一处理token失效问题


使用http response 拦截器 在main.js中添加

import axios from 'axios';

  

axios.interceptors.response.use(response => {
  if (response) {
    switch (response.data.code) {
      case 403: //与后台约定登录失效的返回码,根据实际情况处理
        localStorage.clear();     //删除用户信息
        //如果超时就处理 ,指定要跳转的页面(比如登陆页)
        Message({
          message: 'token失效,请重新登录!',
          type: 'warning',
          center: true,
          onClose:function () {
            console.log('关闭了看下')
            router.replace({
              path: '/user/login',
            })
          }
        });
    }
  }
  return response;
}, error => {
  return Promise.reject(error.response.data) //返回接口返回的错误信息
})

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM