mh-two-thousand-and-two
2024-04-16 d4211fd96865e58217d63efaf4d8f6609fb24ae6
src/store/index.js
@@ -6,7 +6,24 @@
const store = new Vuex.Store({
   strict: true,
   state:{
      // 用户账号
      username:'sdf',
      // 中国人物数据库中的id
   },
   getters,
   mutations:{
      Set_UserName(state,username){
         console.log(username,'uuu');
         state.username=username
      }
   },
   actions:{
      setUserName({commit},user){
         commit('Set_UserName',user)
      }
   },
   modules: { user },
   plugins:[function(store){
      // 监听mutaions 记录state到本地存储
@@ -16,7 +33,7 @@
      })
      // 读取缓存中state
      if(uni.getStorageSync('state')){
         console.log(state,'aaaaaaaaastatestatestate');
         // console.log(state,'aaaaaaaaastatestatestate');
         store.replaceState(Object.assign({},store.state,uni.getStorageSync('state')))
      }
   }]