Chapter 28: Vue Slots

Slots (also called content distribution or composability outlets)

Slots are Vue’s way of letting a parent component inject custom content (HTML, components, text…) into a child component at specific places — without the child having to know in advance what that content will be.

In simple words:

The child says: “Hey parent, I have some holes in my design — you can put whatever you want here.” The parent says: “Great, here’s some custom content — put it in those holes.”

This is what makes components truly reusable and composable — the same component can look completely different depending on what the parent decides to put inside.

Why Slots Are So Important (Real-World Motivation)

Without slots you would have to:

  • Pass huge strings via props → ugly & unsafe (v-html)
  • Use lots of boolean props or variant props → explodes into dozens of props
  • Duplicate almost-identical components → maintenance nightmare

With slots:

  • One component can serve many different use-cases
  • Parent controls layout & content
  • Child controls structure & styling
  • Perfect separation of concerns

Types of Slots in Vue 3 (2026)

  1. Default slot (unnamed / main content)
  2. Named slots (multiple specific places)
  3. Scoped slots (child passes data back to parent — most powerful)
  4. Dynamic slot names (rare but useful)

Let’s go through them one by one with real examples.

1. Default Slot (Most Common)

Child: Card.vue (a simple wrapper)

vue

Parent usage (different content every time)

vue

→ Same <Card> component — completely different appearance & purpose

2. Named Slots (Multiple Specific Places)

Already shown in the example above — use <template #name> or v-slot:name

Shorthand syntax (very common):

vue

3. Scoped Slots (Child → Parent Data Passing – The Superpower)

This is where slots become really powerful.

The child can pass data back to the parent so the parent can decide how to render that slot.

Child: ProductList.vue

vue

Parent usage – customize rendering

vue

→ Parent decides how each item looks — child only provides the data & loop

Quick Summary Table – Slots in Vue 3 (2026)

Slot Type Syntax in Parent Syntax in Child Use Case / Power Level
Default slot <Card>Content here</Card> <slot /> Main content ★★☆☆☆
Named slot <template #header>…</template> <slot name=”header” /> Multiple sections ★★★☆☆
Scoped slot <template #item=”{ product }”>…</template> <slot name=”item” :product=”product”> Child → parent data ★★★★★
Fallback content Default content inside <slot> Safety net
Dynamic slot name <template #[slotName]>…</template> <slot :name=”dynamicName” /> Rare / advanced

Pro Tips from Real 2026 Projects

  • Prefer scoped slots over passing render functions or huge props
  • Use default slot content as fallback → makes component more forgiving
  • Name slots clearly: header, footer, item, actions, icon, badge…
  • For UI libraries → almost every component should have at least one slot
  • Scoped slots + TypeScript → excellent autocompletion

Your mini practice:

  1. Create Modal.vue with header, body (default), footer slots
  2. Use it twice: one with simple text, one with form inside body
  3. Add scoped slot for footer that receives isLoading prop

Any part still fuzzy? Want me to show:

  • Scoped slots with TypeScript typing?
  • Slots vs props vs provide/inject?
  • Real UI library example (Card with image slot, actions slot)?
  • Fallback content + conditional slots?

Just tell me — we’ll build the next beautiful example together 🚀

Happy slotting from Hyderabad! 💙

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *