vuex持久化插件

178 阅读1分钟
//需要先下载插件
npm install vuex-persistedstate --save 或者 使用
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,
   }),
 ],
 //会自动保存状态,刷新时不会丢失
})