Concept Flow - Events for child to parent communication
Child Component
Parent Component
Parent updates state or reacts
The child sends an event with data upward, and the parent listens and reacts to it.
<template> <Child @notify="handleNotify" /> </template> <script setup> function handleNotify(message) { alert(message) } </script>
| Step | Action | Component | Event Emitted | Parent Listener | Parent Reaction |
|---|---|---|---|---|---|
| 1 | Child renders | Child | None | None | None |
| 2 | User clicks button in Child | Child | Emits 'notify' with 'Hello!' | Listens for 'notify' | Calls handleNotify('Hello!') |
| 3 | Parent handles event | Parent | None | Received 'notify' | Shows alert with 'Hello!' |
| 4 | Event cycle ends | Both | None | None | No further action |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| message | undefined | 'Hello!' | 'Hello!' | 'Hello!' |
| parentState | initial | initial | updated if any | updated if any |
Child emits event with data using $emit. Parent listens with @eventName in template. Parent handler receives data and updates state. This enables child-to-parent communication. Child cannot directly change parent data. Events flow upward only.