Explain it simply
Slots and Flexible Components, in plain language
Just as props pass data, slots pass template content. Slots are a great fit for wrapper components like cards, modals, and layouts. Named slots let you split things into header/body/footer, and scoped slots let a child hand its data back to the parent's template.
Problem → Why → Solution
The problem — why this concept matters
Mixing up what slots are for versus what props are for
A common mistake
Ending up with an empty UI because no fallback content was provided
Core concept — understand how it works
Build reusable layout components with default, named, and scoped slots.
- props or event
- component and template
- rendered Vue UI
Provide slot content
Core syntax or pattern
<!-- BaseCard.vue -->
<template>
<article class="card">
<header><slot name="title">Untitled</slot></header>
<div><slot /></div>
<footer><slot name="actions" /></footer>
</article>
</template>
<!-- usage -->
<BaseCard>
<template #title>Vue Course</template>
<p>20 practical lessons</p>
<template #actions><button>Start</button></template>
</BaseCard>Build reusable layout components with default, named, and scoped slots.
Read the code step by step
- props or event
<!-- BaseCard.vue -->Just as props pass data, slots pass template content. Slots are a great fit for wrapper components like cards, modals, and layouts. Named slots let you split things into header/body/footer, and scoped slots let a child hand its data back to the parent's template.
- component and template
</template>Build reusable layout components with default, named, and scoped slots.
- rendered Vue UI
</BaseCard>Apply Slots and Flexible Components in a small example and test normal, edge, and failure cases.
- props or event
- component and template
- rendered Vue UI
Success
Provide slot content
Failure
Mixing up what slots are for versus what props are for
Let's break it down simply
Just as props pass data, slots pass template content. Slots are a great fit for wrapper components like cards, modals, and layouts. Named slots let you split things into header/body/footer, and scoped slots let a child hand its data back to the parent's template.
<!-- BaseCard.vue -->
<template>
<article class="card">
<header><slot name="title">Untitled</slot></header>
<div><slot /></div>
<footer><slot name="actions" /></footer>
</article>
</template>
<!-- usage -->
<BaseCard>
<template #title>Vue Course</template>
<p>20 practical lessons</p>
<template #actions><button>Start</button></template>
</BaseCard>Vue Course
20 practical lessons
[Start]Try it yourself
Write a BaseModal component with named slots for header, content, and footer.
Slots — Vue.js
Real-world usage
How to apply it in a real project
Apply Slots and Flexible Components in a small example and test normal, edge, and failure cases.
Mini challenge
Build it yourself
Write a BaseModal component with named slots for header, content, and footer.
- Rebuild the example without copying it
- Test a normal input and an edge case
- Predict the compiler or output result before running it
<!-- BaseCard.vue -->
<template>
<article class="card">
<header><slot name="title">Untitled</slot></header>
<div><slot /></div>
<footer><slot name="actions" /></footer>
</article>
</template>
<!-- usage -->
<BaseCard>
<template #title>Vue Course</template>
<p>20 practical lessons</p>
<template #actions><button>Start</button></template>
</BaseCard>Expected: Provide slot content
Show hint
Apply Slots and Flexible Components in a small example and test normal, edge, and failure cases.
Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- props or event → component and template → rendered Vue UI
- Build reusable layout components with default, named, and scoped slots.
- Mixing up what slots are for versus what props are for
- Apply Slots and Flexible Components in a small example and test normal, edge, and failure cases.
Slots — Vue.js