sunChengjie 11 months ago
parent
commit
02f49f2255
1 changed files with 14 additions and 10 deletions
  1. 14 10
      src/main.js

+ 14 - 10
src/main.js

@@ -55,7 +55,7 @@ Vue.filter('dateFormat', (dataStr) => {
 
 
 
-//Vue.prototype.common=common
+// Vue.prototype.common = common
 // Vue.http.options.emulateJSON = true;
 // Vue.http.options.headers = {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'};
 
@@ -66,13 +66,23 @@ Vue.filter('dateFormat', (dataStr) => {
 /* eslint-disable no-new */
 // 判断userid和openid,userid没有的情况下让他直接去登录,openid没有的情况下让他只走授权
 // 路由前置守卫
+
+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()
         }
@@ -81,10 +91,4 @@ router.beforeEach((to, from, next) => {
     }
 })
 
-new Vue({
-    el: '#app',
-    router,
-    store: store,
-    components: { App },
-    template: '<App/>'
-})
+