[Vuejs]-Vue js send data between two components NO props

0👍

Introducing global state with Vuex is probably the best way to go about this.

Without introducing something new into the system, you can handle this with an event bus. Introducing side channel stuff like this does add complexity to your app but is sometimes necessary.

Then in your components you use them like this

// eventBus.js
import Vue from 'vue';
export const EventBus = new Vue();

// To setup your component to listen and update based on new value
import { EventBus } from './eventBus';
mounted() {
  EventBus.$on('newValue', (val) => this.something = val);
}

// To send out a new value 
EventBus.$emit('newValue', 5);
👤Austio

Leave a comment