Answer the question
In order to leave comments, you need to log in
Why is there multiple triggering of actions/mutations when using dynamic module registration in vuex?
I'm learning vue, there was a problem using dynamic connection of vuex modules.
There is a module that is used only in one section of the application, it hung the registration of the module on the beforeRouteEnter router hook, and the removal of the module on the beforeRouteLeave hook.
Immediately after registration, an action is called that loads data for the connected module from the server.
When you first enter the section, everything works as it should. On subsequent logins, the number of action calls starts to increase.
What could be the reason for this behavior?
Answer the question
In order to leave comments, you need to log in
Understood the problem.
The module was removed incorrectly.
The beforeRouteEnter hook does not have access to the component via this, so you need to use next
beforeRouteEnter(to, from, next) {
next((vm) => {
// vm ссылается на компонент
});
},
beforeRouteLeave(to, from, next) {
this.$store.unregisterModule(name);
next();
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question