下载 :
npm i vuex-persistedstate
配置在store/index.js中,使用插件来做持久化。
import createPersistedstate from 'vuex-persistedstate'
export default createStore({ modules: { user, cart, category },
plugins: [
createPersistedstate({
key: 'client-pc-store', // key 的名字
paths: ['user', 'cart'] // 是一个数组,这里写需要被自动持久化管理的模块的名字
})
] })
本文介绍如何使用vuex-persistedstate插件实现Vuex状态的持久化存储。通过在store/index.js文件中导入并配置插件,指定需要持久化的模块如'user'和'cart',使得应用在刷新或关闭后仍能保留这些状态。
2663

被折叠的 条评论
为什么被折叠?



