[Vuejs]-How to store a 'global var' on the eventbus

0👍

I suspect you are on the brink of turning your system into spaghetti code. You’re already using an event bus, which is a cousin to global variables, and now you want to add a global variable to it.

The normal architecture of a Vue app is "props down, events up". Since you have a master Vue already, you should consider whether you really need to use an eventbus, rather than the more disciplined normal approach. Since you are in the process of learning Vue, you should lean heavily toward doing things in the prescribed way.

The counter should exist in the top-level Vue and be passed to components via props. The components should issue events that the top-level Vue will act on, making the appropriate changes to the counter, and Vue will propagate those changes back down to the components.

👤Roy J

Leave a comment