Vuex持久化存储之vuex-persist

Vuex的状态存储并不能持久化,存储在 Vuex 中的 store 里的数据,只要一刷新页面,数据就丢失了

所以引入vuex-persist 插件,可以自动将 Vuex的 store 数据本地持久化存储

安装: 

npm install --save vuex-persist 

使用: 

import VuexPersist from 'vuex-persist'

const vuexLC = new VuexPersist ({storage: window.localStorage }) 

const store = new Vuex.Store({   

state: { ... },   

mutations: { ... },   

actions: { ... },   

plugins: [vuexLC.plugin]

})

posted on 2020-12-07 17:25  3SU  阅读(470)  评论(0编辑  收藏  举报