DEV Community

Discussion on: Sharing Data Between Components in Vue.js

Collapse
 
giorgosk profile image
Giorgos Kontopoulos 👀 • Edited

Nice writeup Alex, thanks for sharing.

I have forked your example and have made it work with a Global EventBus using EventBus.$emit and EventBus.$on. This way any Component can choose to listen to this event which makes for a cleaner solution I think.

You can see my changes here codesandbox.io/s/mq2yl9lw8p

Do you know why would someone choose one over the other method ?

Collapse
 
franciscosuca profile image
franciscosuca

This was really helpful for a beginner like me, thanks!

Collapse
 
alexmourer profile image
Alex Mourer

Hey George! Your fork looks great, thanks for providing this.

I did look into using EventBus.$emit for the example, but I was trying to keep the components as modular as possible. While creating the file event-bus.js is not a huge lift, it is an additional item the component is dependent on.

I think your solution is 100% acceptable.