Vue 3·Vue from reactivity to a routed app

Emits and slots

Send events up and let parents fill named slots.

Intermediate 13 min read Lesson 7 of 300 Challenge included
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.

Panel.vueJavaScript
<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

Emit a save event

Easy

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 in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 7 of 300 · 0% of course