vuex 数据持久化插件

2020-09-06  本文已影响0人  宏_4491
下包
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
      }
    }
  })]
})
上一篇下一篇

猜你喜欢

热点阅读