0

I'm trying to update a state from another module. The structure is.

store.js
|
|-- yields.js
|
|--analysis (sub-folder)
          |
          |
          ---actions.js
          |
          ---mutations.js
          |
          ---state.js

So as suggested I used this in actions.js:

export const actions = {
  analysisAction({
    commit,
    rootState
  }, input) {
    commit('stateFetchParamsStart', input); // Commit in this module
    commit('yields/statePRdate', input, {
      root: true
    }); // Commit in another module
  },...

Added a mutation in yields.js:

const mutations = {
  statePRdate: (state, input) => {
    state.PRdate = input;
  },...

And call it in a computed property like:

computed: {
    start: {
        get() {
                return this.$store.state.analysis.fetchParams.start
            },
            set(value) {this.$store.dispatch('analysisAction', value);
            }
    },...

methods: {
    ...mapActions([
            'otherActions',
            'analysisAction'
        ]),

I also tried the namespaced variant, but it's giving me an error. With this solution the mutation for state.fetchParams.start is working but I get the error: [vuex] unknown mutation type: yields/statePRdate

So it cant call the mutation of the other state.

why me
  • 301
  • 1
  • 2
  • 15
  • Check for this response https://stackoverflow.com/questions/42606091/change-another-module-state-from-one-module-in-vuex – Vasile Radeanu Jan 27 '21 at 13:54
  • @Radeanu That's exactly how I did it. Just the value set to null. But I need to set it to value. – why me Jan 27 '21 at 14:01
  • 2
    If you're not using namespaced modules, you have to remove `yields/` from the second commit. Can't mix and match namespaced syntax – Dan Jan 27 '21 at 14:10

1 Answers1

1

Shout-out to @Dan who provided the solution. I just needed to remove the '/yields' to avoid mixing namespaced and not namespaced syntax.

why me
  • 301
  • 1
  • 2
  • 15