Explorar o código

修复调用 Vuex.Store 子模块的 mutations 不正确导致的异常

调用的方式应该是 this.$store.commit('user/SET_USER_INFO',),其中 user 是子模块,SET_USER_INFO 是子模块中的 mutations
reghao %!s(int64=4) %!d(string=hai) anos
pai
achega
39bc4093d4

+ 1 - 1
src/components/setting/user-base-setting.vue

@@ -100,7 +100,7 @@ export default {
       }).then(response => response.json())
         .then(json => {
           if (json.status === 200) {
-            this.$store.commit('setUserInfo', this.userInfo)
+            this.$store.commit('user/SET_USER_INFO', this.userInfo)
             this.message = '修改成功'
             this.showMessage = true
           } else {

+ 1 - 1
src/components/setting/user-head-setting.vue

@@ -132,7 +132,7 @@ export default {
       }).then(response => response.json())
         .then(json => {
           if (json.status === 200) {
-            this.$store.commit('setUserInfo', this.userInfo)
+            this.$store.commit('user/SET_USER_INFO', this.userInfo)
             this.message = '保存成功!'
             this.showMessage = true
           } else {

+ 1 - 1
src/components/setting/user-password-setting.vue

@@ -139,7 +139,7 @@ export default {
           if (json.status === 200) {
             this.message = '修改成功,即将跳转,请重新登录!'
             this.showMessage = true
-            this.$store.commit('setUserInfo', null)
+            this.$store.commit('user/SET_USER_INFO', null)
             this.$router.push('/login')
           } else {
             this.message = '修改失败!' + json.message

+ 1 - 1
src/components/setting/user-top-image.vue

@@ -132,7 +132,7 @@ export default {
       }).then(response => response.json())
         .then(json => {
           if (json.status === 200) {
-            this.$store.commit('setUserInfo', this.userInfo)
+            this.$store.commit('user/SET_USER_INFO', this.userInfo)
             this.message = '保存成功!'
             this.showMessage = true
           } else {

+ 7 - 7
src/router/index.js

@@ -221,22 +221,22 @@ router.beforeEach((to, from, next) => {
     document.title = to.meta.title
   }
 
+  const vuexStore = router.app.$options.store
   // router.app.$options.store 就是 this.$store
-  if (checkPower.updateUserRole(router.app.$options.store.state.user.userInfo)) {
-    router.app.$options.store.state.user.userInfo.role = 'ROLE_USER'
-    router.app.$options.store.commit('setUserInfo', router.app.$options.store.state.user.userInfo)
+  if (checkPower.updateUserRole(vuexStore.state.user.userInfo)) {
+    vuexStore.state.user.userInfo.role = 'ROLE_USER'
+    vuexStore.commit('SET_USER_INFO', vuexStore.state.user.userInfo)
   }
 
   const date = new Date().getTime()
-  if (router.app.$options.store.state.user.userInfo != null) {
-    // console.log(router.app.$options.store.state.userInfo.expireTime > date, router.app.$options.store.state.userInfo.expireTime, date)
-    if (router.app.$options.store.state.user.userInfo.expireTime > date) {
+  if (vuexStore.state.user.userInfo != null) {
+    if (vuexStore.state.user.userInfo.expireTime > date) {
       if (to.path === '/login') {
         return next({ path: '/' })
       }
       return next()
     } else {
-      router.app.$options.store.commit('setUserInfo', null)
+      vuexStore.commit('user/SET_USER_INFO', null)
       return next({
         path: '/login',
         query: { redirect: to.fullPath }