4

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.js store I need to get the recordType value from abc.js

1

1 Answer 1

5

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']
    });
  }
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.