[Vuejs]-Vue.js @emit is not picked up by parent

1👍

Child Element

A child element needs to declare the emits.

Options API
export default {
  emits: ['first-emit-name', 'second-emit-name'],
}
Composition API
const emit = defineEmits(['first-emit-name', 'second-emit-name'])

After this, it will forward the declared emits to the parent element in Vue.

Options API
this.$emit('first-emit-name')
this.$emit('second-emit-name')
Composition API
// After const emit declaration
emit('first-emit-name')
emit('second-emit-name')

Parent Element

<ChildElement @first-emit-name="(e) => ..." @second-emit-name="(e) => ...">

Leave a comment