徐勤民 4 months ago
parent
commit
f45130bd1f
1 changed files with 6 additions and 5 deletions
  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
 }