I have two independent components that are not directly related to each other. However, I want them to be able to communicate so that when an event is triggered in one component, the other component can respond accordingly.
For example, let's consider a component named "reset-component" which emits an event called "reset".
<reset-component @reset="actionReset" />
Additionally, we have a "grid-component" that needs to listen for the "reset" event emitted by the "reset-component" and take specific actions in response.
<grid-component />
What are my options for achieving this functionality? The only approach I've thought of involves emitting a global event using an EventBus and then having the grid-component listen for that global event. But is this considered a best practice? Or could it actually be seen as an anti-pattern?
// Reset component
EventBus.$emit('reset')
// Grid component
created()
{
EventBus.$on('reset', () => {
doSomething()
})
}