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