使用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) //返回接口返回的错误信息
})

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2021-07-13
  • 2021-10-12
  • 2022-03-09
  • 2021-08-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案