vue-persist 为 vuex 持久化!!
npm install --save vuex-persist
import VuexPersistence from 'vuex-persist'
const vuexLocal = new VuexPersistence({ storage: window.localStorage }) const store = new Vuex.Store<State>({ state: { ... }, mutations: { ... }, actions: { ... }, plugins: [vuexLocal.plugin] })
vuex 即可实现 持久化!(刷新不丢数据)
例如 index.js
import Vue from 'vue' import Vuex from 'vuex' import VuexPersistence from 'vuex-persist' const vuexLocal = new VuexPersistence({ storage: window.localStorage }) Vue.use(Vuex) import PostClass from './modules/PostClass' export default new Vuex.Store({ plugins: [vuexLocal.plugin], state: { /** * 登陆前的url..用于登录后跳转到 此url */ beforeLoginUrl: '', /** * 当前登陆用户的菜单 */ menuList: [], /** * */ postClass: [] }, modules: { PostClass }, mutations: { setBlUrl(state, path) { state.beforeLoginUrl = path; }, setMenuList(state, payload) { state.menuList = payload } } })