uni-app vuex持久化存储

uniapp yekong 405℃

安装依赖

npm install --save vuex-persistedstate

修改store/index.js

import createPersistedState from 'vuex-persistedstate'

const vuexPersisted = new createPersistedState({
    storage: {
        getItem: key => uni.getStorageSync(key),
        setItem: (key, value) => uni.setStorageSync(key, value),
        removeItem: key => uni.removeStorageSync(key)
    }
})

const store = new Vuex.Store({
    plugins:[vuexPersisted]
})
喜欢 (0)