Vue Scoped Slots

Vue Scoped Slots
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 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)
| Feature | Scoped Slots | Props |
|---|---|---|
| Pass data | Child → Parent | Parent → Child |
| Control UI | Parent | Child |
| Flexibility | High | Medium |
| Use case | Layout rendering | Configuration |
- 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
| Task | Syntax |
|---|---|
| Default scoped slot | v-slot="{ data }" |
| Named scoped slot | #name="{ data }" |
| Slot prop | <slot :item="item" /> |
| Destructure | { item, index } |
| Default slot name | default |
Conclusion
Vue scoped slots are one of the most powerful patterns in Vue.
They let you build highly reusable, customizable components without sacrificing clarity.
