安装
npm install -S vuex-persist(yarn add vuex-persist)
使用:
/store/index.js引入vuex-persist配置:
import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersistence from 'vuex-persist'
import user from './modules/user' // 自定义的modules
import getters from './getters' // 自定义的getters
Vue.use(Vuex)
const vuexLocal = new VuexPersistence({
storage: window.sessionStorage
})
const store = new Vuex.Store({
modules: {
user
},
getters,
plugins: [vuexLocal.plugin]
})
export default store