vue2 下载vuex固化插件
下载 yarn add vuex-persistedstate --save
//在vuex初始化时导入插件
import persist from 'vuex-persistedstate'
//并使用
export default new Vuex.Store({
state: {
},
mutations: {
},
actions: {
},
modules: {
},
plugins: [
new persist({
storage: window.localStorage,
}),
],
//会自动保存状态,刷新时不会丢失
})