Skip to content

Commit e4e179c

Browse files
docs: improve scoped slots explanation of mixing default and named sc… (#2853)
* docs: improve scoped slots explanation of mixing default and named scoped slots * Update src/guide/components/slots.md --------- Co-authored-by: Natalia Tepluhina <[email protected]>
1 parent 851edc2 commit e4e179c

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/guide/components/slots.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -443,34 +443,38 @@ Note the `name` of a slot won't be included in the props because it is reserved
443443

444444
If you are mixing named slots with the default scoped slot, you need to use an explicit `<template>` tag for the default slot. Attempting to place the `v-slot` directive directly on the component will result in a compilation error. This is to avoid any ambiguity about the scope of the props of the default slot. For example:
445445

446+
```vue-html
447+
<!-- <MyComponent> template -->
448+
<div>
449+
<slot :message="hello"></slot>
450+
<slot name="footer" />
451+
</div>
452+
```
453+
446454
```vue-html
447455
<!-- This template won't compile -->
448-
<template>
449-
<MyComponent v-slot="{ message }">
456+
<MyComponent v-slot="{ message }">
457+
<p>{{ message }}</p>
458+
<template #footer>
459+
<!-- message belongs to the default slot, and is not available here -->
450460
<p>{{ message }}</p>
451-
<template #footer>
452-
<!-- message belongs to the default slot, and is not available here -->
453-
<p>{{ message }}</p>
454-
</template>
455-
</MyComponent>
456-
</template>
461+
</template>
462+
</MyComponent>
457463
```
458464

459465
Using an explicit `<template>` tag for the default slot helps to make it clear that the `message` prop is not available inside the other slot:
460466

461467
```vue-html
462-
<template>
463-
<MyComponent>
464-
<!-- Use explicit default slot -->
465-
<template #default="{ message }">
466-
<p>{{ message }}</p>
467-
</template>
468-
469-
<template #footer>
470-
<p>Here's some contact info</p>
471-
</template>
472-
</MyComponent>
473-
</template>
468+
<MyComponent>
469+
<!-- Use explicit default slot -->
470+
<template #default="{ message }">
471+
<p>{{ message }}</p>
472+
</template>
473+
474+
<template #footer>
475+
<p>Here's some contact info</p>
476+
</template>
477+
</MyComponent>
474478
```
475479

476480
### Fancy List Example {#fancy-list-example}

0 commit comments

Comments
 (0)