Browse Source

账号判断写在app.vue

qukaidi 4 years ago
parent
commit
48ced60c6e
2 changed files with 10 additions and 14 deletions
  1. 10 1
      App.vue
  2. 0 13
      pages/home/index.vue

+ 10 - 1
App.vue

@@ -1,10 +1,13 @@
 <script>
-	import {mapMutations} from 'vuex'
+	import {mapState,mapMutations} from 'vuex'
 	export default {
 		// 此处globalData为了演示其作用,不是uView框架的一部分
 		globalData: {
 			username: '白居易'
 		},
+		computed: {
+			...mapState(['hasLogin'])
+		},
 		methods:{
 			...mapMutations(['login'])
 		},
@@ -13,6 +16,12 @@
 			// 注意,需要在/main.js中实例化Vue之后引入如下(详见文档说明):
 			// import httpInterceptor from '@/common/http.interceptor.js'
 			// Vue.use(httpInterceptor, app)
+			if (!this.hasLogin) {
+				this.$u.route({
+					url: "pages/login/index",
+					type: "redirect"
+				})
+			}
 			let storeInfo=uni.getStorageSync("storeInfo")||"";
 			if(storeInfo.storeId){
 				uni.getStorage({

+ 0 - 13
pages/home/index.vue

@@ -48,10 +48,6 @@
 
 <script>
 	import {
-		mapState,
-		mapMutations
-	} from 'vuex'
-	import {
 		request
 	} from '../../common/request/request'
 	require("promise.prototype.finally").shim()
@@ -71,12 +67,6 @@
 			uni.$on('login', (data) => {
 				this.loginStatus = data.msg
 			})
-			if (!this.hasLogin) {
-				this.$u.route({
-					url: "pages/login/index",
-					type: "redirect"
-				})
-			}
 		},
 		onReady() {
 			if (this.loginStatus == "登录成功") {
@@ -103,9 +93,6 @@
 					uni.hideLoading();
 				})
 		},
-		computed: {
-			...mapState(['hasLogin'])
-		},
 		methods: {
 			//轮播图
 			getBanners() {