模块状态返回空页创建方法

时间:2020-07-01 19:14:00

标签: javascript vue.js vuex

我正在尝试从页面创建方法中的vuex模块获取一些信息,但它始终返回null。我可以看到状态不是null Vue开发人员工具/ Vuex选项卡,当我尝试获取其单个值时,我获取了null。这是我的vuex模块文件代码:

import Vue from "vue";

export default {
  state: () => ({
    restaurantInfo: null
  }),
  mutations: {
    SET_RESTAURANT(state, rest) {
      state.restaurantInfo = rest;
    }
  },

  actions: {
    async getRestaurantInfo({ commit }, sessionId) {
      await Vue.prototype.$Service.get(
        "tr-TR/Restaurant",
        {
          params: {
            sessionId: sessionId
          }
        },
        response => {
          if (response) {
            commit("SET_RESTAURANT", response);
          }
        }
      );
    }
  },

  getters: {
    loggedInRestaurant(state) {
      return state.restaurantInfo;
    }
  }
};

从这个创建的方法中,我试图获取restaurantInfo,我得到的是'null':

created() {
    this.$store.dispatch(
      "getZones",
      this.$store.state.restaurant.restaurantInfo
    );
  },

我的商店文件是这样的:

import Vue from "vue";
import Vuex from "vuex";

import auth from "./modules/auth";
import menu from "./modules/menu";
import leftMenu from "./modules/leftMenu";
import restaurant from "./modules/restaurant";
import zone from "./modules/zone";
import table from "./modules/table";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    loader: false,
    modals: {
      newTableModal: {
        visible: false,
        cleanData: null
      },
      newMenuModal: {
        visible: false,
        clearData: null
      },
      newZoneModal: {
        visible: false,
        clearData: null
      }
    }
  },
  mutations: {
    SET_MODAL(state, obj) {
      state.modals["" + obj[0]] = obj[1];
    },

    SET_LOADER(state, loaderState) {
      state.loader = loaderState;
    }
  },

  actions: {},
  modules: {
    leftMenu,
    menu,
    auth,
    restaurant,
    zone,
    table
  }
});

0 个答案:

没有答案