--- name: component-slots description: Pass template content to child components with default, named, and scoped slots --- # Component Slots Slots allow parent components to pass template content into child components. ## Basic Slot Child component with slot outlet: ```vue ``` Parent passes slot content: ```vue-html Click me! ``` Renders as: ```html ``` ## Fallback Content Provide default content when no slot content is provided: ```vue ``` ## Named Slots Use multiple slots with names: ```vue ``` Use `v-slot` or `#` shorthand to target named slots: ```vue-html

Main content goes here

``` ## Scoped Slots Pass data from child to parent slot content: ```vue ``` Receive slot props in parent: ```vue-html {{ slotProps.text }} {{ slotProps.count }} {{ text }} {{ count }} ``` ### Named Scoped Slots ```vue-html ``` ## Conditional Slots Check if a slot has content using `$slots`: ```vue ``` ## Dynamic Slot Names ```vue-html ``` ## Renderless Components Components that only provide logic via scoped slots: ```vue ``` Usage: ```vue-html Mouse: {{ x }}, {{ y }} ``` > Note: Composables are often preferred over renderless components for pure logic reuse. ## Render Scope - Slot content has access to parent scope - Slot content does NOT have access to child scope - Use scoped slots to expose child data