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-implicit-default-content.md
1---2title: Non-Template Content Is Implicitly Default Slot Content3impact: LOW4impactDescription: Unexpected content placement when mixing named slots with loose content5type: gotcha6tags: [vue3, slots, named-slots, default-slot, implicit-behavior]7---89# Non-Template Content Is Implicitly Default Slot Content1011**Impact: LOW** - When using named slots, any top-level content not wrapped in a `<template>` tag is automatically treated as default slot content. This implicit behavior can cause confusion about where content will render.1213## Task Checklist1415- [ ] Understand that loose content goes to the default slot16- [ ] Use explicit `<template #default>` when clarity matters17- [ ] Keep slot content organization intentional1819**The Implicit Behavior:**20```vue21<script setup>22import BaseLayout from './BaseLayout.vue'23</script>2425<template>26<BaseLayout>27<template #header>28<h1>Page Title</h1>29</template>3031<!-- These are IMPLICITLY in the default slot -->32<p>First paragraph of main content.</p>33<p>Second paragraph of main content.</p>3435<template #footer>36<p>Footer content</p>37</template>38</BaseLayout>39</template>40```4142The two `<p>` elements are automatically placed in `<slot>` (the default slot) in the child component.4344**Equivalent Explicit Version:**45```vue46<template>47<BaseLayout>48<template #header>49<h1>Page Title</h1>50</template>5152<!-- Explicit default slot -->53<template #default>54<p>First paragraph of main content.</p>55<p>Second paragraph of main content.</p>56</template>5758<template #footer>59<p>Footer content</p>60</template>61</BaseLayout>62</template>63```6465## When Implicit Behavior Causes Confusion6667**Scattered Content:**68```vue69<template>70<BaseLayout>71<template #header>72<h1>Title</h1>73</template>7475<p>Content A</p> <!-- Goes to default slot -->7677<template #sidebar>78<nav>Navigation</nav>79</template>8081<p>Content B</p> <!-- Also goes to default slot! -->8283<template #footer>84<p>Footer</p>85</template>8687<p>Content C</p> <!-- Also goes to default slot! -->88</BaseLayout>89</template>90```9192All three `<p>` elements end up in the default slot together, which may not be the intended order or grouping.9394**Clearer with Explicit Default:**95```vue96<template>97<BaseLayout>98<template #header>99<h1>Title</h1>100</template>101102<template #default>103<p>Content A</p>104<p>Content B</p>105<p>Content C</p>106</template>107108<template #sidebar>109<nav>Navigation</nav>110</template>111112<template #footer>113<p>Footer</p>114</template>115</BaseLayout>116</template>117```118119## Best Practices120121| Scenario | Recommendation |122|----------|---------------|123| Only default slot used | Implicit is fine |124| Mixed named + default slots | Consider explicit `#default` |125| Complex layouts | Always use explicit templates |126| Team/shared codebase | Prefer explicit for clarity |127128## The Child Component129130```vue131<!-- BaseLayout.vue -->132<template>133<div class="layout">134<header>135<slot name="header"></slot>136</header>137138<aside>139<slot name="sidebar"></slot>140</aside>141142<main>143<!-- All implicit content ends up here -->144<slot></slot>145</main>146147<footer>148<slot name="footer"></slot>149</footer>150</div>151</template>152```153154## Reference155- [Vue.js Slots - Named Slots](https://vuejs.org/guide/components/slots.html#named-slots)156