我有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.js
商店中,我需要从abc.js
获取recordType值
答案 0 :(得分:1)
您可以使用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']
});
}
};