npm install --save vuex-persistedstate
const state = {
name: '',
phone: '',
avatar: ''
}
const mutations = {
}
export default {
namespaced: true,
state,
mutations
}
// ...
import createPersistedState from 'vuex-persistedstate'
import admin from './modules/admin'
const adminState = createPersistedState({
paths: ['admin']
// paths: ['admin.name'] // admin.js中的'name'持久化
})
// sessionStorage
const activePath = createPersistedState({
storage: window.sessionStorage,
paths: ['activeIndex']
})
export default new Vuex.Store({
// ...
plugins: [adminState,activePath]
})
脉望