Vuex的状态存储并不能持久化,存储在 Vuex 中的 store 里的数据,只要一刷新页面,数据就丢失了
所以引入vuex-persist 插件,可以自动将 Vuex的 store 数据本地持久化存储
- 安装:
npm install --save vuex-persist - 使用(store.js里面的基础配置):
import VuexPersist from ‘vuex-persist’
const vuexLC = new VuexPersist ({storage: window.localStorage })
const store = new Vuex.Store({
state: { … },
mutations: { … },
actions: { … },
plugins: [vuexLC.plugin]
})