Vue 3 v-slot Directive
v-slot The directive is used to represent named or scoped slots, for content distribution between components.
Basic Explanation
v-slot The directive is used to provide content for slots or receive props passed by slots. It is the core way to achieve component content distribution in Vue.
- Shorthand: #
- Expected type: JavaScript expression (optional, only needed when receiving props)
- Purpose: represents a named slot or scoped slot.
Basic Usage
1. Named Slots
Example
Page title
Main content area
Footer information
2. Shorthand Form
Example
Title
Title
3. Scoped Slots
Scoped slots allow child components to pass data to parent components:
Example
Username: {{ slotProps.user.name }}
Vue 3 Built-in Directives