Chapter 24: Vue $emit() Method

Vue: $emit() (and its modern Composition API version emit()).

This is the official way a child component talks back to its parent.

In Vue we have a very clear direction rule:

  • Props go down (parent → child)
  • Events go up (child → parent)

$emit() (or emit()) is how the child announces that “something happened” — and optionally sends data along with that announcement.

Why Do We Need $emit / emit?

Imagine these real situations:

  • User clicks “Add to Cart” inside a ProductCard component → parent (shopping page) needs to know so it can update the cart count in the header
  • User toggles a checkbox inside TodoItem → parent needs to mark that todo as done in the central list
  • Form inside a modal emits “submit” → parent closes modal and saves data
  • A dropdown inside a FilterPanel selects a category → parent filters the product list

Without events, the child would have to directly mutate parent’s data (very bad — breaks reactivity rules and makes debugging hell).

With $emit / emit → child stays dumb & reusable, parent stays in control.

Modern Way in Vue 3: defineEmits + emit() (2026 standard)

In <script setup> we never use this.$emit anymore — we use:

TypeScript

Real, Complete Example – TodoItem that Emits Events

Child: TodoItem.vue

vue

Parent: TodoList.vue (using v-for + listening to emits)

vue

Key Takeaways – $emit / emit in 2026

Feature Old Options API Modern <script setup> Notes / Best Practice
Declare events emits: [‘toggle’, ‘delete’] defineEmits<…>() Use TS types for safety
Emit event this.$emit(‘toggle’, id) emit(‘toggle’, id) No this — much cleaner
With payload this.$emit(‘update’, id, value) emit(‘update:text’, id, newText) Any number of args
v-model support this.$emit(‘update:value’, val) emit(‘update:modelValue’, val) Enables v-model on component
Event name convention kebab-case (update:user) kebab-case in template, camel in JS Auto-converted

Quick Summary – When to Emit

Child Action Emit Name Convention Parent Listens With Payload Example
Checkbox toggled toggle @toggle id
Item deleted delete @delete id
Text edited update:text or update @update:text id, newText
Form submitted submit @submit form data object
Item selected (dropdown) select / update:value @select / @update:value selected value

Pro Tips from Real Projects

  • Always declare events with defineEmits — gives autocompletion & catches typos
  • Use kebab-case for event names in templates (@update:text)
  • For two-way binding → use update:propName pattern → enables v-model
  • Keep payloads small & serializable (numbers, strings, plain objects — avoid functions, DOM nodes)
  • Child should never mutate props — always emit → parent updates

Want to go deeper?

  • Make TodoItem support v-model:text?
  • Show custom modal component that emits close and confirm?
  • Explain $emit in Options API for legacy code?
  • Events with multiple arguments or complex payloads?

Just tell me — we’ll keep building together 🚀

Happy emitting from Hyderabad! 💙

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *