itsource

Vuex에 있는 다른 상점의 getter를 어떻게 부르죠?

mycopycode 2022. 8. 16. 23:37
반응형

Vuex에 있는 다른 상점의 getter를 어떻게 부르죠?

있습니다vuex가게abc.js:

import Vue from 'vue';

const state = {
  recordType: null
};

const getters = {

  recordType: state => state.recordType,

};
.... other code

나는 다른 것을 가지고 있다.vuex가게xyz.js:

import { API } from '@/api';
import Vue from 'vue';

const state = {
  messages: null
};

const getters = {
  messages: state => state.messages || [],
};

const actions = {
  async openRecord({ dispatch, rootState, commit, state }, record) {

    // api data
    const response = await API.post('api/openrecord/', {
      recordUid: record.recordUid,

      //**** HELP !!! HERE ****//
      recordType: // *** HERE I need to get the recordType getter from abc.js

    });

  }

};

곧.xyz.jsstore recordType 값을 가져와야 합니다.abc.js

rootGetters 속성은 네임스페이스를 지정하여 사용할 수 있습니다.

rootGetters['abc/recordType']

사용자의 경우 다음과 같습니다.

const actions = {
  async openRecord({ dispatch, rootGetters, commit, state }, record) {
    // api data
    const response = await API.post('api/openrecord/', {
      recordUid: record.recordUid,
      recordType: rootGetters['abc/recordType']
    });
  }
};

언급URL : https://stackoverflow.com/questions/51604004/how-do-i-call-a-getter-from-another-store-in-vuex

반응형