作者:小豇豆和花椰菜 | 来源:互联网 | 2023-06-01 19:25
项目中使用了vuex-persist进行数据的持久化, 已经将vuex的数据存储的localStorage中,但是刷新的时候,并没有从localStorage读取到vuex中, 是否要单独调用初始化方
项目中使用了vuex-persist进行数据的持久化, 已经将vuex的数据存储的localStorage中,
但是刷新的时候,并没有从localStorage读取到vuex中,
是否要单独调用初始化方法呢还是我配置的不对?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import Vue from 'vue'
import Vuex from 'vuex'
import actions from './actions'
import * as getters from './getters'
import state from './state'
import mutations from './mutations'
import VuexPersistence from 'vuex-persist'
Vue.use(Vuex)
const vuexLocal = new VuexPersistence({
key: 'ht',
storage: window.localStorage,
})
const store = new Vuex.Store({
actions,
getters,
state,
mutations,
plugins: [vuexLocal.plugin]
})
export default store |