Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vue 3 debugging reference for reactivity issues, computed errors, watcher bugs, async failures, and SSR hydration problems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
reference/slot-name-reserved-prop.md
1---2title: Slot Name is Reserved and Not Included in Slot Props3impact: LOW4impactDescription: Expecting 'name' in scoped slot props when it's reserved causes confusion5type: gotcha6tags: [vue3, slots, scoped-slots, reserved-props, naming]7---89# Slot Name is Reserved and Not Included in Slot Props1011**Impact: LOW** - When using scoped slots, the `name` attribute on the `<slot>` element is reserved for identifying the slot. It is not passed as part of the slot props to the parent component.1213## Task Checklist1415- [ ] Don't expect `name` in slot props - it's reserved16- [ ] Use a different prop name if you need to pass a name value17- [ ] Remember only explicitly bound attributes become slot props1819**Incorrect Expectation:**20```vue21<!-- ChildComponent.vue -->22<template>23<div>24<slot name="header" title="Welcome"></slot>25</div>26</template>27```2829```vue30<!-- ParentComponent.vue -->31<ChildComponent>32<template #header="props">33<!-- props = { title: "Welcome" } -->34<!-- 'name' is NOT included! -->35{{ props.name }} <!-- undefined -->36{{ props.title }} <!-- "Welcome" -->37</template>38</ChildComponent>39```4041**If You Need to Pass a "Name" Value:**42```vue43<!-- ChildComponent.vue -->44<template>45<div>46<!-- Use a different prop name like 'slotName' or 'label' -->47<slot name="header" :label="slotLabel" :title="title"></slot>48</div>49</template>5051<script setup>52const slotLabel = 'header'53const title = 'Welcome'54</script>55```5657```vue58<!-- ParentComponent.vue -->59<ChildComponent>60<template #header="{ label, title }">61<h2>{{ title }}</h2>62<span>Section: {{ label }}</span>63</template>64</ChildComponent>65```6667## What Gets Passed as Slot Props6869| Attribute on `<slot>` | Passed to Parent? |70|----------------------|-------------------|71| `name` | No (reserved for slot identification) |72| `:text="message"` | Yes, as `text` |73| `:count="5"` | Yes, as `count` |74| `v-bind="object"` | Yes, spreads object properties |75| `class="..."` | No (not bound with `:`) |7677## Multiple Named Slots Example7879```vue80<!-- TabPanel.vue -->81<template>82<div class="tabs">83<slot name="tab1" :active="activeTab === 1" :label="'First Tab'"></slot>84<slot name="tab2" :active="activeTab === 2" :label="'Second Tab'"></slot>85</div>86</template>8788<script setup>89import { ref } from 'vue'90const activeTab = ref(1)91</script>92```9394```vue95<!-- Usage -->96<TabPanel>97<template #tab1="{ active, label }">98<!-- 'name' not available, but 'label' is -->99<button :class="{ active }">{{ label }}</button>100</template>101102<template #tab2="{ active, label }">103<button :class="{ active }">{{ label }}</button>104</template>105</TabPanel>106```107108## Reference109- [Vue.js Slots - Scoped Slots](https://vuejs.org/guide/components/slots.html#scoped-slots)110