重新整理不清除狀態管理、重新整理不清楚指定資料的狀態管理
阿新 • • 發佈:2020-08-18
重新整理不清除所有狀態管理器:
下載依賴:vuex-persistedstate
mport Vue from 'vue'; import Vuex from 'vuex'; import getters from './getters'; import user from './modules/user'; import permission from './modules/permission'; import filterbox from './modules/filterbox'; import createPersistedState from 'vuex-persistedstate'; Vue.use(Vuex); const store= new Vuex.Store({ plugins: [createPersistedState()], getters, state: { maptype: '2d', }, modules: { user, permission, filterbox } }); export default store;
重新整理不清除指定狀態管理器:
import Vue from 'vue'; import Vuex from 'vuex'; import getters from './getters'; import user from'./modules/user'; import permission from './modules/permission'; import filterbox from './modules/filterbox'; import videoList from './modules/videoList'; import conponentAttrConfig from './modules/componentAttrConfig'; import CreatePersistedState from 'vuex-persistedstate'; Vue.use(Vuex); const state = { maptype:'2d' } // 需要持久化的資料放到reducer裡 const vuexPersisted = new CreatePersistedState({ key: 'VuexPersisted', storage: window.sessionStorage, reducer(val) { return { maptype: val.maptype, permission: { addRoutes: val.permission.addRoutes }, user: { change: val.user.change, isHome: val.user.isHome, treeInfo: val.user.treeInfo, sidebarMenuList: val.user.sidebarMenuList } } } }) const store = new Vuex.Store({ modules: { user, permission, videoList, filterbox, conponentAttrConfig }, state, getters, plugins: [vuexPersisted] }); export default store;