zoukankan      html  css  js  c++  java
  • vue里面的store,刷新变量不会消失

    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;
    

      

  • 相关阅读:
    Docker-compose编排微服务顺序启动解决方案
    在笔记本上使用virtualbox搭建lvs dr 实验遇到的问题
    MongoDB安装配置(RedHat/CentOS)
    wget 用法
    Ubuntu查看crontab运行日志
    CentOS-6.5安装Zabbix 3.0.4
    centos 6 安装vsftpd与PAM虚拟用户
    python socket常用接口说明
    cmake 构建工程
    std::vector的下标访问和迭代器访问的效率
  • 原文地址:https://www.cnblogs.com/sinceForever/p/15529425.html
Copyright © 2011-2022 走看看