소스 검색

fix:路由前置守卫

sunChengjie 1 년 전
부모
커밋
2c1787201c
1개의 변경된 파일7개의 추가작업 그리고 5개의 파일을 삭제
  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,