Use $slots to check if a slot was provided: v-if="$slots.header".
Dynamic slot names: <template #[dynamicSlotName]> for runtime-determined slots.
Details
Slots are Vue's content distribution mechanism, equivalent to React's children and render props. They allow parent components to inject content into child component templates. Named slots organize multiple content areas, and scoped slots pass data back to the parent for custom rendering.
Trade-offs:
Slot-heavy components can be verbose in usage — many <template #name> blocks
Scoped slots add complexity — the data flow (child-to-parent via slot props) is the reverse of props
TypeScript support for slot props is improving but still requires explicit typing via defineSlots()
When NOT to use:
When the component always renders the same structure — just use props for data
When only a string or simple value varies — a prop is simpler than a slot
For behavior sharing — use composables instead of renderless components with scoped slots
Read the instructions and examples in this document.
Apply the patterns to your implementation, adapting to your specific context.
Verify your implementation against the details and edge cases listed above.
Harness Integration
Type: knowledge — this skill is a reference document, not a procedural workflow.
No tools or state — consumed as context by other skills and agents.
Success Criteria
The patterns described in this document are applied correctly in the implementation.
Edge cases and anti-patterns listed in this document are avoided.
1---2name: vue-slots-pattern3description: Vue Slots Pattern4---5# Vue Slots Pattern67> Use named, scoped, and dynamic slots to build flexible, composable component APIs89## When to Use1011- Building layout components (Card, Modal, Page) where the consumer controls the content12- Creating data-driven components (tables, lists) where the consumer controls how each item renders13- Designing component libraries with maximum flexibility1415## Instructions16171. Use `<slot>` for the default slot, `<slot name="header">` for named slots.182. Pass data to the consumer via scoped slots: `<slot :item="item">`.193. The consumer accesses scoped data with `<template #slotName="{ item }">`.204. Provide fallback content inside `<slot>` tags for when the consumer does not fill the slot.2122```vue23<!-- Card.vue -->24<template>25 <div class="card">26 <div class="header"><slot name="header">Default Header</slot></div>27 <div class="body"><slot /></div>28 <div class="footer"><slot name="footer" /></div>29 </div>30</template>3132<!-- Consumer -->33<Card>34 <template #header><h2>Custom Title</h2></template>35 <p>Body content goes in the default slot</p>36</Card>37```38395. Use `$slots` to check if a slot was provided: `v-if="$slots.header"`.406. Dynamic slot names: `<template #[dynamicSlotName]>` for runtime-determined slots.4142## Details4344Slots are Vue's content distribution mechanism, equivalent to React's `children` and render props. They allow parent components to inject content into child component templates. Named slots organize multiple content areas, and scoped slots pass data back to the parent for custom rendering.4546**Trade-offs:**4748- Slot-heavy components can be verbose in usage — many `<template #name>` blocks49- Scoped slots add complexity — the data flow (child-to-parent via slot props) is the reverse of props50- TypeScript support for slot props is improving but still requires explicit typing via `defineSlots()`5152**When NOT to use:**5354- When the component always renders the same structure — just use props for data55- When only a string or simple value varies — a prop is simpler than a slot56- For behavior sharing — use composables instead of renderless components with scoped slots5758## Source5960https://patterns.dev/vue/slots-pattern6162## Process63641. Read the instructions and examples in this document.652. Apply the patterns to your implementation, adapting to your specific context.663. Verify your implementation against the details and edge cases listed above.6768## Harness Integration6970- **Type:** knowledge — this skill is a reference document, not a procedural workflow.71- **No tools or state** — consumed as context by other skills and agents.7273## Success Criteria7475- The patterns described in this document are applied correctly in the implementation.76- Edge cases and anti-patterns listed in this document are avoided.
Run npx skillmds@latest add intense-visions/vue-slots-pattern in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Vue Slots Pattern It is listed under Web & Frontend on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Intense-Visions (@intense-visions) published this skill. Their other Agent Skills are listed on their SkillMD profile.