2

Let's say we have a store with two modules, A and B.

All I need is: Access a state property of A while initializing the state of B.

Accessing that property can be done with 'rootState' if the case was trying to access the property inside a getter, action or mutation. But how can I do that while initializing the state?

Example:

A.js

export default  {
   state:{
      x:5
   }
}

B.js

export default  {
   state:{
      foo: 3+ (how to access A.x here?) // this should be 8
   }
}

index.js would look something like this

import moduleA from './modules/A'
import moduleB from './modules/B'

new Vuex.Store({
    modules: {
        A: moduleA,
        B: moduleB,
    },
})
Magdy
  • 21
  • 1
  • Hey mate, take a look [here](https://stackoverflow.com/questions/41366388/vuex-access-state-from-another-module) pls – Nikola Pavicevic Oct 06 '21 at 10:39
  • 1
    @NikolaPavicevic I've visited this link before I posted the question but it doesn't help in my use case. It helps when you need to reference other module state in a modules (action-getter or mutation). Because Vuex gives the option of using rootState as a parameter in all these. What I do need is use that other module state in a module state initialization. Please review the example I supplied. Thank you. – Magdy Oct 06 '21 at 11:45

0 Answers0