mh-two-thousand-and-two
2024-04-12 abdded451d7afb1922417ee4c937c531babc6bdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getter.js'
import user from './module/user'
Vue.use(Vuex)
 
const store = new Vuex.Store({
    strict: true,
    getters,
    modules: { user },
    plugins:[function(store){
        // 监听mutaions 记录state到本地存储
        store.subscribe((mutation,state)=>{
            uni.setStorageSync('state',state)
            console.log(state,'statestatestate');
        })
        // 读取缓存中state
        if(uni.getStorageSync('state')){
            console.log(state,'aaaaaaaaastatestatestate');
            store.replaceState(Object.assign({},store.state,uni.getStorageSync('state')))
        }
    }]
})
 
export default store