Vue $emit() Method

Vue Tutorial

Vue $emit() Method

In Vue.js, Vue $emit() Method is used for child → parent communication.

It allows a child component to send events (and data) to its parent.


 What is Vue $emit() Method?

$emit() triggers a custom event from a child component that the parent listens to.

 Data flow:

Parent → Child (props)
Child → Parent (emit)
  • Clean communication
  • One-way data flow
  •  Core Vue concept

 Basic Syntax

Parent listens using:


 Basic Example

 Child Component


 


Parent Component


 


 Emitting Data with $emit()

You can pass arguments with the event.

Child

Parent


 Multiple Arguments


$emit() with v-for Components

Very common in lists.

Child:

Parent:


 Declaring Events with emits (Vue 3 – Recommended)

Helps with validation & readability.

With validation:


$emit() with v-model (Behind the Scenes)

Used by:


 Event Naming Rules

  •  Use kebab-case in templates
  • Use camelCase in JS

$emit() vs Props (Important)

FeatureProps$emit()
DirectionParent → ChildChild → Parent
PurposePass dataSend events
MutabilityRead-onlyTrigger action
  •  Props for data
  • $emit() for actions

 Common Mistakes

  •  Mutating props instead of emitting
  • Forgetting to listen in parent
  •  Using $emit() between siblings
  •  Overusing emits for state (use store)

 Best Practices

  •  Use $emit() for user actions
  •  Declare events with emits
  •  Keep event names clear (save, delete, update)
  • Don’t emit too deeply (consider state management)

 Summary Table

TaskUse
Child → Parent$emit()
Send data$emit('event', data)
Validate eventsemits
Update v-modelupdate:modelValue
Lists actions$emit() + v-for

 Conclusion

The $emit() method is the backbone of component communication in Vue.
Mastering $emit() helps you build clean, scalable, and maintainable component-based apps.

You may also like...