徐勤民 il y a 1 mois
Parent
commit
f45130bd1f
1 fichiers modifiés avec 6 ajouts et 5 suppressions
  1. 6 5
      src/api/index.js

+ 6 - 5
src/api/index.js

@@ -7,10 +7,6 @@ import { ElMessage } from "element-plus"
 
 // 错误处理
 function errorHandle(data) {
-  if (data.message === "请登录")
-    CommonUtil.debounce(() => {
-      router.push("/login")
-    }, 1000)
   CommonUtil.debounce(() => {
     ElMessage.error(data.message)
   }, 1000)
@@ -19,7 +15,12 @@ function errorHandle(data) {
 // 处理handle
 function handle(data) {
   if (data.code !== 200) {
-    throw Error(data.msg)
+    if (data.code === 401) {
+      CommonUtil.debounce(() => {
+        router.push("/login")
+      }, 1000)
+    } else
+      throw Error(data.msg)
   }
   return data.data
 }