[Vuejs]-Catch value on event emit from child component in parent component

0👍

this.$on will listen for events emitted by the same component. To listen for events emitted by a child component you should assign an event listener on the child component in the template section of the parent component. So in the template section of form-preview.vue you should have something like this ..

<vue-datetimepicker @change="handleChange" ... / >

Then in the script section in the parent component you can define your handleChange event handler ..

methods: {
    handleChange(value) {
        console.log('Event from child component emitted', value)
    }
}

Note that the event handler will automatically receive any data emitted with the event. If you want to make it explicit you can use @change="handleChange($event)"

Leave a comment