Browse Source

fix:路由前置守卫

sunChengjie 11 months ago
parent
commit
2c1787201c
1 changed files with 7 additions and 5 deletions
  1. 7 5
      src/main.js

+ 7 - 5
src/main.js

@@ -51,17 +51,19 @@ Vue.prototype.$wx = wx
 /* eslint-disable no-new */
 router.beforeEach((to, from, next) => {
 	if (to.matched.some(record => record.meta.needLogin)) { // 判断该路由是否需要登录权限
-		if (localStorage.getItem('userId')) { // 判断当前用户的登录信息loginInfo是否存在
-			next();
+		//登录判断
+		if (!localStorage.getItem('userId')) { // 判断当前用户的登录信息loginInfo是否存在
+			next('/login')
+		} else if (!localStorage.getItem('openid')) {
+			this.getOpenid()
 		} else {
-			next({
-				path: '/Login'
-			})
+			next()
 		}
 	} else {
 		next();
 	}
 })
+
 new Vue({
 	el: '#app',
 	router,