Overview
Components can emit custom events to communicate with their parent. This enables child-to-parent communication in Vue’s unidirectional data flow.Emitting Events
With <script setup>
Array Syntax
runtime-core/src/apiSetupHelpers.ts:135-137
Object Syntax
runtime-core/src/apiSetupHelpers.ts:138-140
Without <script setup>
Type-Based Emits Declaration
With TypeScript, declare emits using pure types:runtime-core/src/apiSetupHelpers.ts:119-127
Function Syntax
Listening to Events
In Templates
Usev-on or @ shorthand:
Inline Handlers
Event Validation
Object Emits Options
runtime-core/src/componentEmits.ts:36-39
Validator Functions
runtime-core/src/componentEmits.ts:140-148
Event Naming
camelCase vs kebab-case
Emit events using camelCase in JavaScript:Event Name Convention
Use descriptive, action-oriented names:EmitFn Type
Theemit function is typed based on declared events:
runtime-core/src/componentEmits.ts:93-109
EmitsToProps Type
Emits are automatically converted to props for type checking:runtime-core/src/componentEmits.ts:43-58
Event Bubbling
Vue component events do not bubble by default:v-on object syntax:
v-model Events
Components can usev-model by emitting update:modelValue:
Multiple v-models
Event Implementation
The internalemit function:
runtime-core/src/componentEmits.ts:111-150
Advanced Patterns
Typed Event Payloads
Event Composition
Conditional Events
Best Practices
- Always declare emits explicitly for better documentation and validation
- Use type-based declarations with TypeScript for compile-time safety
- Validate event payloads in development using validator functions
- Use descriptive names that clearly indicate the action
- Keep payloads simple - pass only necessary data
- Document events in component JSDoc comments
- Avoid side effects in emit calls - keep them pure
- Use v-model pattern for two-way binding scenarios
Common Patterns
Confirmation Dialog
Form Events
Async Operations
Related APIs
- Props - Learn about receiving data from parent
- v-model - Learn about two-way binding
- defineModel - Learn about the model helper
- Provide/Inject - Learn about dependency injection