소스 검색

onLaunch只走一次,避免无限循环

xiaohaizhao 4 달 전
부모
커밋
651dd657a1
2개의 변경된 파일18개의 추가작업 그리고 18개의 파일을 삭제
  1. 18 0
      App.vue
  2. 0 18
      pages/login/login.vue

+ 18 - 0
App.vue

@@ -2,6 +2,24 @@
 import { ref, getCurrentInstance } from 'vue'
 export default {
 	onLaunch: function () {
+		const { $Http } = getCurrentInstance().proxy;
+		if (wx.getStorageSync('userMsg').token) {
+			$Http.basic({
+				"classname": "common.adspace.adspace",
+				"method": "query_adspacelist", //查询轮播图
+				content: {
+					nocache: true
+				}
+			}).then(res => {
+				if (res.code == 1) {
+					uni.removeStorageSync('banner')
+					uni.setStorageSync('banner', res.data);
+					uni.redirectTo({
+						url: '/pages/index/index',
+					});
+				}
+			})
+		}
 	},
 	onShow: function () {
 		try {

+ 0 - 18
pages/login/login.vue

@@ -51,24 +51,6 @@ onLoad(() => {
         phonenumber.value = storedPhone;
         isAgreement.value = true;
     }
-
-    if (wx.getStorageSync('userMsg').token) {
-        $Http.basic({
-            "classname": "common.adspace.adspace",
-            "method": "query_adspacelist", //查询轮播图
-            content: {
-                nocache: true
-            }
-        }).then(res => {
-            if (res.code !== 0) {
-                uni.removeStorageSync('banner')
-                uni.setStorageSync('banner', res.data);
-                uni.redirectTo({
-                    url: '/pages/index/index',
-                });
-            }
-        })
-    }
 });
 
 // 登陆按钮相关