Vue Scoped Slots

Vue Tutorial

Vue Scoped Slots

In Vue.js, scoped slots allow a child component to pass data to the parent’s slot content.

They give you maximum flexibility by separating data (child) from presentation (parent).


 What are Scoped Slots?

Scoped slots are slots with data (called slot props) provided by the child component.

 Data flow:

Child (provides data) → Parent (decides how to render)
  •  Child controls what data is exposed
  • Parent controls how it is displayed

 Why Scoped Slots are Needed

Without scoped slots:

  • Parent cannot access child’s internal data

With scoped slots:

  • Parent can customize rendering using child’s data

Perfect for:

  • Tables

  • Lists

  • Cards

  • UI libraries


 Basic Scoped Slot Example

Child Component (UserCard.vue)


 


 Parent Component

  • { user } comes from the child slot props

 Scoped Slot with Shorthand

  • #default = default slot

 Named Scoped Slots

Child


 Parent


 Scoped Slots in v-for (Very Common)

Child (List Component)


 Parent

  •  Parent controls how each item is rendered

 Scoped Slots with Tables (Real-World Example)

Child (DataTable.vue)


Parent

  •  Widely used in data grids & admin panels

 Destructuring & Defaults


 Scoped Slots vs Props (Important)

FeatureScoped SlotsProps
Pass data Child → Parent Parent → Child
Control UI Parent Child
FlexibilityHighMedium
Use caseLayout renderingConfiguration
  • Props → configure components
  • Scoped slots → customize rendering

 Common Use Cases

  • Custom list rendering

  • Table rows & cells

  • Dropdown options

  • Reusable UI libraries

  • Layout components


 Common Mistakes

  •  Confusing direction of data
  •  Overexposing internal data
  •  Using scoped slots for simple cases
  •  Complex slot APIs

 Best Practices

  •  Expose minimal data via slot props
  •  Use clear slot prop names
  • Prefer scoped slots for layout customization
  •  Document slot contracts

 Summary Table

TaskSyntax
Default scoped slotv-slot="{ data }"
Named scoped slot#name="{ data }"
Slot prop<slot :item="item" />
Destructure{ item, index }
Default slot namedefault

Conclusion

Vue scoped slots are one of the most powerful patterns in Vue.
They let you build highly reusable, customizable components without sacrificing clarity.

You may also like...