Overview
Slots allow parent components to pass template content into child components, enabling flexible content composition.Basic Slots
Defining Slots
Using Slots
Fallback Content
Provide default content when no slot content is provided:Named Slots
Defining Named Slots
Using Named Slots
v-slot Shorthand
Scoped Slots
Scoped slots allow slots to access child component data.Defining Scoped Slots
Using Scoped Slots
Named Scoped Slots
Slot Types
Slot Function Type
runtime-core/src/componentSlots.ts:30-32
Slots Interface
runtime-core/src/componentSlots.ts:38
SlotsType Helper
runtime-core/src/componentSlots.ts:41-43
Type-Safe Slots
With <script setup>
runtime-core/src/apiSetupHelpers.ts:234-241
Without <script setup>
Accessing Slots
In <script setup>
runtime-core/src/apiSetupHelpers.ts:393-395
In Options API
Dynamic Slot Names
Conditional Slots
Slot Normalization
Internal slot normalization:runtime-core/src/componentSlots.ts:92-118
renderless Components
Components that only provide logic via scoped slots:Slot Performance
Stable Slots
Slots marked as stable skip forced updates:runtime-core/src/componentSlots.ts:63-66
Compiled Slots
Compiler-generated slots are optimized:runtime-core/src/componentSlots.ts:74-81
Advanced Patterns
Slot Forwarding
Forward all slots to a child component:Slot Composition
Higher-Order Slots
Best Practices
- Use named slots for multiple injection points
- Provide fallback content for better defaults
- Type slots with
defineSlots()in TypeScript - Use scoped slots to share component state
- Check slot existence before conditional rendering
- Keep slot APIs stable to avoid unnecessary re-renders
- Document slot props in component comments
- Use v-slot shorthand (#) for cleaner templates
Common Patterns
List with Custom Items
Modal with Multiple Sections
Data Provider
Related APIs
- Props - Learn about component props
- Events - Learn about component events
- Render Functions - Learn about programmatic rendering