sunChengjie 11 months ago
parent
commit
863b78fa8c
1 changed files with 11 additions and 30 deletions
  1. 11 30
      src/main.js

+ 11 - 30
src/main.js

@@ -49,13 +49,22 @@ Vue.prototype.$wx = wx
 
 // })
 /* eslint-disable no-new */
+let overallExample = new Vue({
+	el: '#app',
+	router,
+	store: store,
+	components: { App },
+	template: '<App/>',
+
+})
+
 router.beforeEach((to, from, next) => {
 	if (to.matched.some(record => record.meta.needLogin)) { // 判断该路由是否需要登录权限
 		//登录判断
-		if (!localStorage.getItem('userId')) { // 判断当前用户的登录信息loginInfo是否存在
+		if (!localStorage.getItem('userId')) { // 判断当前用户的登录信息userId是否存在
 			next('/login')
 		} else if (!localStorage.getItem('openid')) {
-			this.getOpenid()
+			overallExample.getOpenid()
 		} else {
 			next()
 		}
@@ -64,31 +73,3 @@ router.beforeEach((to, from, next) => {
 	}
 })
 
-new Vue({
-	el: '#app',
-	router,
-	store: store,
-	components: {
-		App
-	},
-	template: '<App/>'
-})
-/* router.beforeEach(function(to, from, next) {
-  if (to.meta.needLogin) {
-	//页面是否登录
-	if (sessionStorage.getItem("userId")) {
-	  //存储中是否有token(uid)数据
-	  next(); //表示已经登录
-	} else {
-	  //next可以传递一个路由对象作为参数 表示需要跳转到的页面
-	  next({
-		path: "Login"
-	  });
-	}
-  } else {
-	//表示不需要登录
-	next(); //继续往后走
-  }
-}); */
-
-