user4001262
user4001262

Reputation: 11

Emit data between components (Event listener in vue?)

I'm kind of new to Vue and I'm trying to emit data between different components.

I have 2 components I need to emit their data together: First component is the Item Selector. Second component is Filter Navigation Bar.

the logic: The navigation bar contains a filter section, I've created an ItemSelector component and import it to the navigation bar. I want the data selected in the item selector will be emited to the container and a table will be draw by that information. I created the logic of the table, and tried to import the item selector component directly to the container and passing the data using emit, and it worked great. The problem is I've added one more page to the cycle. Right now, the ItemSelector component emits its data to the FilterContainer component, and now this data should be emited to the container!

Is there any way to catch all those events in a seperate component, compute the data and emit it all over the app?

Upvotes: 0

Views: 806

Answers (1)

Hung Nguyen
Hung Nguyen

Reputation: 1156

You can use a global event bus which can listen/emit event on global scope of your app.

Another approach is using vuex which store all global states of your app.

If you have small app, i think you should use event bus because it simpler than vuex.

Upvotes: 1

Related Questions