I have vuex a store abc.js:
import Vue from 'vue';
const state = {
recordType: null
};
const getters = {
recordType: state => state.recordType,
};
.... other code
The I have other vuex store 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
});
}
};
So on
xyz.jsstore I need to get the recordType value fromabc.js
You can use the rootGetters property, along with specifying namespace :
rootGetters['abc/recordType']
In your case, it gives :
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']
});
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With