A
A
Artem Prokhorov2021-07-28 18:47:39
Vue.js
Artem Prokhorov, 2021-07-28 18:47:39

How to get the state from another Vuex module inside a mutation and not an action?

I give such a clarification, since everywhere there is the same copy-paste of this one:
context.rootState.instance.session
there is no context in mutations (right :D ?).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
inFureal, 2021-07-28
@inFureal

import store from './path/to/store'

export default {
    mutations: {
        yourCoolMutation() {
            store.state.another.something // Тут я могу ошибиться
        }
    }
}

H
hitrick, 2021-07-29
@hitrick

Mutations are atomic actions, if you want to edit a neighboring module, then create (wrap) an action and call the desired action inside it, which will change the state.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question