import Vue from "vue"; import Vuex from "vuex"; import VuexPersistence from "vuex-persist"; const vuexLocal = new VuexPersistence({ storage: window.sessionStorage, }); Vue.use(Vuex); const store = new Vuex.Store({ state: { urlId: "", platFrom: "", // 首页平台 href: "", artPlatFrom: "", // 文章平台 firstUrl: "", // 第一次进入时的链接 homePageName: "", // 首页标题 homeDesc: "", // 首页描述 contextPath: "", // 首页接口给的变量 artcleTitle: "", // 文章标题 activeName: "", // 栏目id otherParam: "" }, getter: { getUrlId(state) { return state.urlId; }, getPlatFrom(state) { return state.platFrom; }, getHref(state) { return state.href; }, getArtPlatFrom(state) { return state.artPlatFrom; }, getFirstUrl(state) { return state.firstUrl; }, getHomePageName(state) { return state.homePageName; }, getHomeDesc(state) { return state.homeDesc; }, getContextPath(state) { return state.contextPath; }, getOtherParam(state){ return state.otherParam }, getArtcleTitle(state) { return state.artcleTitle }, getActiveName(state){ return state.activeName } }, mutations: { setUrlId(state, value) { state.urlId = value; }, setPlatFrom(state, value) { state.platFrom = value; }, setHref(state, value) { state.href = value; }, setArtPlatFrom(state, value) { state.artPlatFrom = value; }, setFirstUrl(state, value) { state.firstUrl = value; }, setHomePageName(state, value) { state.homePageName = value; }, setHomeDesc(state, value) { state.homeDesc = value; }, setContextPath(state, value) { state.contextPath = value; }, setOtherParam(state, value){ state.otherParam = value }, setArtcleTitle(state, value){ state.artcleTitle = value }, setActiveName(state, value) { state.activeName = value } }, actions: { setUrlIdAction({ commit }, value) { commit("setUrlId", value); }, setPlatFromAction({ commit }, value) { commit("setPlatFrom", value); }, setHrefAction({ commit }, value) { commit("setHref", value); }, setArtPlatFromAction({ commit }, value) { commit("setArtPlatFrom", value); }, setFirstUrlAction({ commit }, value) { commit("setFirstUrl", value); }, setHomePageNameAction({ commit }, value) { commit("setHomePageName", value); }, setHomeDescAction({ commit }, value) { commit("setHomeDesc", value); }, setContextPathAction({ commit }, value) { commit("setContextPath", value); }, setOtherParamAction({ commit }, value) { commit("setOtherParam", value) }, setArtcleTitleAction({ commit }, value) { commit("setArtcleTitle", value) }, setActiveNameAction({ commit }, value) { commit("setActiveName", value) } }, plugins: [vuexLocal.plugin], }); export default store;