Ver Fonte

fix homepage userInfo

wangJJ há 5 anos atrás
pai
commit
0a96435328

+ 5 - 2
src/components/commons/Header2.0.vue

@@ -86,7 +86,7 @@
   } from '@/js/index'
   import Http from '@/js/http.js'
   import Apis from '@/js/api.js'
-
+  import { mapGetters , mapActions} from 'vuex'
   export default {
     name: "Header2.0",
     data(){
@@ -118,6 +118,7 @@
         deep: true
     },
     methods: {
+        ...mapActions(['setUser']),
         gotoHome(){
             this.$router.push('/home');
         },
@@ -159,6 +160,7 @@
 
                 getCurrentUser().then((res) => {
                     storageSave('user', res)
+                    this.setUser(res);
                     this.user = res
                     this.rolesPermissions = getRolesPermissions(res.roleList)
                     storageSave('rolesPermissions', getRolesPermissions(res.roleList))
@@ -185,6 +187,7 @@
             this.rolesPermissions = getRolesPermissions(res.roleList)
             storageSave('rolesPermissions', getRolesPermissions(res.roleList))
             console.log('用户信息加载成功')
+
             this.isLogin = true
             this.fullScreenLoading = false
         },
@@ -379,7 +382,7 @@
         // if (storageGet('user' != null)){
         //   this.isLogin = true
         // }
-    }
+    },
   }
 </script>
 

+ 10 - 1
src/pages/Homepage/Homepage.vue

@@ -154,6 +154,9 @@
         currTab: 'homepage'
       }
     },
+    computed: {
+      ...mapGetters(['getUserInfo'])
+    },
     methods: {
       loadData() {
         this.showLoading();
@@ -254,9 +257,15 @@
         this.user = storageGet('user') && storageGet('user').userVO;
       }
     },
-    mounted() {
+    mounted(){
       this.setUserInfo();
       this.loadData();
+    },
+    watch:{
+      getUserInfo(val){
+        this.setUserInfo();
+        this.loadData();
+      }
     }
   }
 </script>

+ 11 - 2
src/store/index.js

@@ -8,8 +8,8 @@ const store = new Vuex.Store({
     isLogin:false,
     techArticleList: ['sss'],// 技术文章
     activeTab:'',
-    homeData:{}
-
+    homeData:{},
+    user:{}
   },
   mutations:{
     setTechArticleList(state,techArticleList){
@@ -21,6 +21,9 @@ const store = new Vuex.Store({
     setHomeData(state,homeData){
       store.state.homeData = homeData;
     },
+    setUserInfo(state,userInfo){
+      store.state.user = userInfo
+    }
   },
   actions:{
     setTechArticleList({commit},techArticleList){
@@ -31,6 +34,9 @@ const store = new Vuex.Store({
     },
     setHomeData({commit},homeData){
       commit('setHomeData', homeData)
+    },
+    setUser({commit},userInfo){
+      commit('setUserInfo', userInfo)
     }
   },
   getters:{
@@ -43,6 +49,9 @@ const store = new Vuex.Store({
     getHomeData: () => {
       return store.state.homeData;
     },
+    getUserInfo:()=>{
+      return store.state.user;
+    }
   },
   modules:{