408249787@qq.com hace 2 semanas
padre
commit
4b003c52ef
Se han modificado 1 ficheros con 14 adiciones y 3 borrados
  1. 14 3
      pages/home/home.vue

+ 14 - 3
pages/home/home.vue

@@ -250,17 +250,25 @@ export default {
           text: '我的'
         }
       ],
-      show: false
+      show: false,
+      // OAuth 登录中标志位,防止 onShow 提前触发 initData 导致 401
+      oauthLogging: false
     }
   },
   onLoad(options) {
-    this.initData()
     if (options.code) {
+      // 有 OAuth code 时先完成登录,再加载数据,避免 initData 在无 token 时触发 401
+      this.oauthLogging = true
       this.login(options.code)
+    } else {
+      this.initData()
     }
   },
   onShow() {
-    this.initData()
+    // OAuth 登录过程中不加载数据,等登录完成后再加载
+    if (!this.oauthLogging) {
+      this.initData()
+    }
   },
   methods: {
     login(code) {
@@ -284,6 +292,9 @@ export default {
         })
         .then(res => {
           this.show = false
+          this.oauthLogging = false
+          // 登录成功后加载首页数据
+          this.initData()
         })
     },
     handleRepair() {