[Vuejs]-How to get value from emit event without v-on directive?

0👍

The typical & easy way is to simply use an event bus. There are several different methods to create a global event bus. In my setup I do it as follows

In the main js…

Vue.prototype.$Bus = new Vue(); 

Then in your child component, or a sibling or anywhere really…

this.$Bus.$emit('myEvent');

Then in your other component listen for the event. Perhaps on mount hook…

mounted(){
        this.$Bus.$on('myEvent', function(){
            console.log('receive the event!')
        } );
    }
👤skribe

Leave a comment