I'm currently utilizing Vue.js version 2.5.x.
Within my small project, I have set up an event bus (similar to the example provided here).
The event bus has been globally registered in the Vue prototype as $eventBus
.
Next, I developed a component that emits an event using the following code snippet:
this.$eventBus.$emit('actionCompleted')
Additionally, I created another component that listens for this event and triggers its own function (myMethod
) upon receiving it, as demonstrated below:
export default {
created: function () {
this.$eventBus.$on('actionCompleted', this.myMethod)
},
methods: {
myMethod () {
console.log('myMethod called')
}
}
}
Everything is functioning correctly so far, but now I am facing a question: how can I include an object when emitting my custom event in order to pass additional information to the listeners?