Trying to make use of the EventBus in Vue.js to transfer data from one method to another. In my setup, I've got two methods named one()
and two()
. Here's how I'm implementing the EventBus:
one() {
EventBus.$emit("this:that", data);
}
And then, in my second method, it looks something like this:
two() {
EventBus.$on('this:that', data => {
window.open(data.link, '_blank');
});
}
Whenever I invoke the one()
method for the first time, it successfully opens a new tab. However, on subsequent calls, it opens multiple tabs - one additional tab with each call. The issue persists until the page is refreshed and the method is called again (resulting in just a single new tab). I did attempt utilizing EventBus.$once
but encountered a scenario where no tab was opened at all.
I'm seeking guidance on preventing the proliferation of tabs, ensuring that each invocation of the method only results in a single new tab, regardless of the number of prior calls before refreshing the page.
Your assistance would be greatly valued!