Vuex 持久化----解决刷新页面,数据丢失

1,利用localStorage或者是sessionStorage在vuex操做store的时候同时对存储操做vue

2,利用插件 vuex-persistedstate (Persist Vuex state with localStorage ,默认存储到localStorage)vuex

  • Installation

$ npm install vuex-persistedstate

 在store下的index.js中npm

import createPersistedState from "vuex-persistedstate"
const store = new Vuex.Store({
  // ...
  plugins: [createPersistedState()]
})

这样就能够了。session

相关文章
相关标签/搜索