Bladeren bron

添加token过期跳转

aaa 3 jaren geleden
bovenliggende
commit
47adfdb34e
1 gewijzigde bestanden met toevoegingen van 8 en 1 verwijderingen
  1. 8 1
      src/plugins/modules/axios.js

+ 8 - 1
src/plugins/modules/axios.js

@@ -1,7 +1,8 @@
 "use strict";
 
 import axios from "axios";
-// import store from "@/store";
+import store from "@/store";
+import router from "@/router";
 import { getCookie } from "@/utils/cookie";
 import { AUTH_TOKEN_FRONT, AUTH_TOKEN_END } from "@/common/Constant";
 import { getAllPromise } from "@/utils/tools";
@@ -115,6 +116,12 @@ _axios.interceptors.response.use(
       // store.dispatch("user/logout");
       return Promise.reject(error);
     }
+    if (status === 412) {
+        message.error("您的登录已过期,请重新登录");
+        store.commit('user/SET_LOGOUT'); // 存用户信息
+        // window.location.reload();
+        router.push({ name: 'login' });
+    }
     if (status < 200) {
       message.warning(`未处理的消息响应,状态码:${status}`);
     } else if (status >= 300 && status < 400) {