用sessionstorage 或者 localstorage 存储数据
存储: sessionStorage.setItem( '名', JSON.stringify(值) )使用: sesconst vuexLocal = new VuexPersistence({storage: window.localStorage})sionStorage.getItem('名') ---得到的值为字符串类型,用JSON.parse()去引号;
vuex-persist
安装
npm install --save vuex-persistoryarn add vuex-persist
使用
const vuexLocal = new VuexPersistence({storage: window.localStorage})const store = new Vuex.Store({state: { ... },mutations: { ... },actions: { ... },plugins: [vuexLocal.plugin]})
通过以上设置,在图3中各个页面之间跳转,如果刷新某个视图,数据并不会丢失,依然存在,并且不需要在每个 mutations 中手动存取 storage
