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

VAAA
  • 14,531
  • 28
  • 130
  • 253
  • 2
    Possible duplicate of [Vuex: Access State From Another Module](https://stackoverflow.com/questions/41366388/vuex-access-state-from-another-module) – Jacob Goh Jul 31 '18 at 01:46

1 Answers1

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']
    });
  }
};
Pierre Gerbaud
  • 131
  • 1
  • 5