Chapter 30: Vue Scoped Slots

Scoped Slots

This is the feature that truly makes Vue components composable powerhouses. Once you master scoped slots, you will feel like you unlocked a cheat code for building flexible, reusable UI libraries and complex layouts.

First — Very Clear Mental Model

A normal (non-scoped) slot is like this:

Child component: “I have a hole here — parent, give me any HTML/content you want.” Parent: “Here’s some markup — put it in the hole.”

A scoped slot adds one super-important twist:

Child component: “I have a hole here — and by the way, here is some data I have (product, item, user, isOpen, index…). Parent, you can use that data to decide how to fill the hole.”

In other words:

  • Child provides data to the parent
  • Parent decides the rendering using that data

This reverses the usual data-flow direction for that particular piece of content — child → parent.

Classic Real-World Example Everyone Should Build Once

Child: ProductList.vue (a reusable list that doesn’t decide how items look)

vue

Parent — total freedom how each item looks

vue

Key Takeaways – Why Scoped Slots Are So Powerful

Aspect What it means Why it matters in 2026
Child controls data Decides what data is available (:product, :index, :is-new, helper functions) Child owns business logic
Parent controls rendering Decides layout, classes, extra markup, icons, badges… Parent owns UI decisions
Fallback content <slot> can have default markup if parent doesn’t provide slot Component is usable out-of-the-box
Multiple scoped slots You can have several: #item, #empty, #loading, #header… Very flexible layouts
TypeScript + scoped slots defineSlots<{ item: { product: Product; isNew: boolean } }>() Autocompletion & safety

Common Scoped Slot Patterns You Will See Everywhere

  • Lists / Tables / Grids → #item, #header, #empty, #loading
  • Modals / Dialogs → #trigger (button that opens), #content
  • Accordions / Tabs → #title, #content with :isOpen
  • Dropdowns / Selects → #option with :item, :selected
  • Data-driven cards → #card with :data, :index

Quick Syntax Reference (2026 Style)

Goal Child (provides slot) Parent (uses slot) – recommended shorthand Parent – full verbose syntax
Default scoped slot <slot :item=”item” /> <MyComp v-slot=”{ item }”>…</MyComp> <template v-slot:default=”{ item }”>…</template>
Named scoped slot <slot name=”item” :product=”product” /> <template #item=”{ product }”>…</template> <template v-slot:item=”{ product }”>…</template>
Shorthand without template tag <MyComp #item=”{ product }”>…</MyComp>
Multiple slots <slot name=”header” /> <slot name=”footer” /> <template #header>…</template> #footer …

Your Mini Practice Challenge

  1. Create Timeline.vue component that loops over events
  2. Use scoped slot#event that receives :event, :index, :is-last
  3. In parent → render each event differently (left/right alignment, icons…)
  4. Add fallback content inside <slot> so it works even without custom slot

Any part still confusing? Want to see:

  • Scoped slots with TypeScript defineSlots typing?
  • Scoped slot inside v-for vs outside?
  • Real UI library pattern (DataTable, Modal, Accordion with slots)?
  • Difference between scoped slots vs props vs provide/inject?

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

Happy scoped-slotting from Hyderabad! 💙

You may also like...

Leave a Reply

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