import Vue from 'vue'
import Vuex, { Store } from 'vuex'
import createPersistedState from "vuex-persistedstate";
import SecureLS from "secure-ls";
const ls = new SecureLS({ isCompression: false });
Vue.use(Vuex)
let store = new Vuex.Store({
/* eslint-disable */
state: {
count: 0,
string: ""
},
mutations: {
increment: state => state.count++,
decrement: state => state.count--,
myString: (state, value) =>
value ? (state.string = value) : (state.string = "")
},
actions: {},
modules: {
},
// 持久化插件
plugins: [
createPersistedState({
storage: {
getItem: key => ls.get(key),
setItem: (key, value) => ls.set(key, value),
removeItem: key => ls.remove(key)
}
})
]
})
export default store;
vuex持久化缓存插件的使用vuex-persistedstate
最新推荐文章于 2024-10-02 15:28:37 发布