You can even make it shorter and use the root Vue
instance as the global Event Hub:
Component 1:
this.$root.$emit('eventing', data);
Component 2:
mounted() {
this.$root.$on('eventing', data => {
console.log(data);
});
}
More Related Contents:
- When should I use Vuex?
- How to add external JS scripts to VueJS Components?
- Vuex state on page refresh
- [Vue warn]: Property or method is not defined on the instance but referenced during render
- How to watch store values from vuex?
- How to listen for ‘props’ changes
- Passing props dynamically to dynamic component in VueJS
- Accessing Vuex state when defining Vue-Router routes
- Vuejs typescript this.$refs..value does not exist
- Is there any way to ‘watch’ for localstorage in Vuejs?
- Vue v-on:click does not work on component
- Vue template or render function not defined yet I am using neither?
- Global data with VueJs 2
- Vue.js – Add class to clicked button
- Use arrow function in vue computed does not work
- How to use .env variables in Nuxt 2 or 3?
- Vue 2 – Mutating props vue-warn
- Make VueJS and jQuery play nice
- Vue.js – How to properly watch for nested data
- VueJs 2.0 emit event from grand child to his grand parent component
- Can I pass parameters in computed properties in Vue.Js
- Vue – Deep watching an array of objects and calculating the change?
- Vue JS: Difference of data() { return {} } vs data:() => ({ })
- Access vue instance/data inside filter method
- Parentheses while calling a method in Vue
- Vue.js – update router view
- How to navigate using vue router from Vuex actions
- Detect Back Button in Navigation Guards of Vue-Router
- Vuex – Computed property “name” was assigned to but it has no setter
- What’s the correct way to pass props as initial data in Vue.js 2?