Emits and slots
Send events up and let parents fill named slots.
What you will be able to do
- Declare events with defineEmits.
- Emit a typed payload.
- Use named slots for layout regions.
- Provide fallback content inside a slot.
In plain English
Emits are the child-to-parent channel. Slots are the parent-to-child content channel. Together they let a component stay reusable without knowing the parent’s data model.
<script setup>
defineEmits<{ close: [] }>()
</script>
<template>
<section>
<header>
<slot name="title">Untitled</slot>
<button @click="$emit('close')">Close</button>
</header>
<slot />
</section>
</template>Your turn
EasyEmit a save event
Declare and emit a save event from a form component.
JAVASCRIPT · starter
defineEmits<{ save: [] }>()Check your understanding before moving on.
Knowledge checkQuestion 1
What is the purpose of a slot?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.