Answer the question
In order to leave comments, you need to log in
How to set up tracking of a variable from Vuex.store in Vue?
There are two components - A and B. I need that when component A made a change in the store, component B learned about it and performed some function.
I tried to fit a watch in B for this, but did not figure out how to do it. It is possible of course from B to interrogate store periodically. Maybe there is another, native way?
Answer the question
In order to leave comments, you need to log in
watch works. For example:
watch: {
'$store.state.module.var': function () { /* ... */ }
}
If you just want to keep track of the change, then getters. In component B, we import them
into computed, useimport { mapGetters } from "vuex"
computed: {
...mapGetters('nameModule', ['nameGetter'])
}
I tried to fit a watch in B for this, but did not figure out how to do it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question