vuex数据持久化 - vuex-persistedstate插件

借助插件来解决vuex页面刷新后数据丢失的问题。

安装插件

npm install vuex-persistedstate --save

  

配置使用(默认存储到localStorage)

import createPersistedState from "vuex-persistedstate"
const dataInfo = {
     state:{},
     mutations:{},
     actions: {},
     getters:{},
     plugins: [createPersistedState()]
}
export default dataInfo

  

存储到sessionStorage

import createPersistedState from "vuex-persistedstate"
const dataInfo = {
     plugins: [createPersistedState({
          state:{},
          mutations:{},
          actions: {},
          getters:{},
          storage:window.sessionStorage
    })]
     
}
export default dataInfo

 

自定义存储

plugins: [
    createPersistedState({ storage: window.sessionStorage })
]

  

posted @ 2021-05-23 16:53  紫诺花开  阅读(204)  评论(0编辑  收藏  举报