0π
In your first component, why donβt you just use mounted
or destroyed
hooks to check for required route changes.
mounted() {
if (this.$route.path === "NewGame") {
EventBus.$emit("changeRoute", true);
}
}
- [Vuejs]-Ant Design input Issue for v-decorator and v-model showing database records for update in Vue JS
- [Vuejs]-How can I add checkbox in v-card in vuetiy
0π
I found out a solution that works for me. I have to user $once
insted of $on
EventBus.$once("changeRoute", payload => {
this.myMethod(); //now is called just once
});
- [Vuejs]-JavaScript can we carry what should be inside then() into method with parameters and call it
- [Vuejs]-Cannot use v-for on stateful component root element because it renders multiple elements
0π
Add the following after your created()
:
destroyed() {
EventBus.$off("changeRoute", payload => {
this.myMethod();
});
},
Notice that instead of $on
I wrote $off
, this will remove the event listener.
Make sure that when you attach a listener, to always remove it when the component is destroyed, otherwise events will be registered several times.
Not entirely sure this will fix your problem as we do not have the full context on how you are using the components, but hopefully it fixes your problem.
- [Vuejs]-Update data depending on another data
- [Vuejs]-Vue.js Passing variable from one component to another (jQuery)
Source:stackexchange.com