Recently, I encountered an issue with the following code:
<component-one></component-one>
<component-two></component-two>
<component-three></component-three>
Specifically, component-two
contains component-three
.
My current setup involves emitting an event in <component-one>
that needs to be caught in <component-three>
.
In <component-one>
, I emit the event like this:
this.$bus.$emit('setSecondBanner', finalBanner);
Then, in <component-three>
, I attempt to catch it:
mounted() {
this.$bus.$on('setSecondBanner', (banner) => {
alert('Caught');
this.banner = banner;
});
},
However, the event is not being caught as expected.
The event bus is defined in my core.js file as follows:
let eventBus = new Vue();
Object.defineProperties(Vue.prototype, {
$bus: {
get: () => { return eventBus; }
}
});
Upon inspecting vue-dev-tools
, I confirm that the event has indeed been fired. So, what could be causing the issue?