下包
npm install vuex-persistedstate --save
store.js 里面导入
import Vue from 'vue'
import Vuex from 'vuex'
import state from "./state";
import mutations from "./mutations";
import actions from "./actions";
import getters from "./getters";
//引入vuex 数据持久化插件
import createPersistedState from "vuex-persistedstate"
Vue.use(Vuex)
export default new Vuex.Store({
state,
mutations,
actions,
getters,
plugins: [createPersistedState({
reducer(val) {
return {
// 只储存state中的token
token: val.token,
roles: val.roles,
tagsList: val.tagsList,
lang:val.lang,
breadList:val.breadList
}
}
})]
})
网友评论