Chapter 29: Vue v-slot

v-slot (and its shorthand #)

This is the official, modern way to work with slots in Vue 3 (since Vue 2.6+ actually, but fully mature in Vue 3).

v-slot replaced the old confusing slot=”name” and slot-scope syntax. It is cleaner, more readable, and supports scoped slots beautifully with TypeScript.

Quick Mental Model – What is v-slot?

Think of a component as a template with holes.

The child component says:

“I have some named holes here — header, footer, actions, item… You (the parent) can decide what content goes into each hole.”

The parent uses v-slot (or #) to fill those holes with custom content.

Syntax Evolution (Why We Use v-slot Now)

Old Vue 2 style (don’t use this anymore)

HTML

Modern Vue 3 style (2026 standard)

HTML

Real, Practical Example – Modal with Named & Scoped Slots

Child Component: Modal.vue (reusable modal)

vue

Parent usage – different modals with same component

vue

Scoped Slots – The Real Power (Child → Parent Data)

Child: ProductGrid.vue (passes product data to parent)

vue

Parent – custom rendering using scoped slot

vue

Quick Syntax Reference – v-slot /

Slot Type Child (defines) Parent (fills) – modern Parent – old / alternative
Default slot <slot /> <MyComp>content</MyComp>
Named slot <slot name=”header” /> <template #header>…</template> <template v-slot:header>…</template>
Scoped slot <slot :item=”item” /> <template #item=”{ item }”>…</template> <template v-slot:item=”slotProps”>…</template>
Shorthand #header or #item=”{ item }”

Pro Tips from Real 2026 Projects

  • Prefer shorthand # — much cleaner & most developers use it
  • Always provide fallback content inside <slot> — makes component more robust
  • Use scoped slots when child has data parent might want to customize rendering with
  • Name slots clearly: header, footer, actions, item, empty, loading…
  • Scoped slots + TypeScript → excellent DX (autocompletion for slot props)

Your mini homework:

  1. Create Accordion.vue with default slot for content and named slot for title
  2. Use it 3 times with different content
  3. Add a scoped slot for icon that receives isOpen state

Any part confusing? Want me to show:

  • Scoped slots with TypeScript interface?
  • Dynamic slot names?
  • Slots vs props vs provide/inject comparison?
  • Real UI library pattern (Card, Modal, Table with slots)?

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

Happy slotting from Hyderabad! 💙

You may also like...

Leave a Reply

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