[Vuejs]-VueJS best way apply css from child to parrents

0👍

You can create a simple EventBus at global level:

const eventBus = new Vue();

And then eventBus.$emit('signal-name', ...args)

Then you can do an array of things like

eventBus.$on(name, callback) -> Create a listener to receive emits

eventBus.$once(name, callback) -> Receive once and remove listener

eventBus.$off(name, callback) -> Remove listener

You can pass some boolean or CSS classes:

eventBus.$emit('signal-name', true) -> and then show something based on it
eventBus.$emit('signal-name', ['is-white', 'is-bold'])

Note: for $off:

  * If no arguments are provided, remove all event listeners;
  * If only the event is provided, remove all listeners for that event;
  * If both event and callback are given, remove the listener for that specific callback only.

Leave a comment