Skip to content

Commit 31a9b42

Browse files
chrisvfritzyyx990803
authored andcommitted
add note about the difference between children and slots
1 parent 285a84f commit 31a9b42

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/guide/render-function.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,21 @@ Vue.component('smart-list', {
366366
})
367367
```
368368

369+
### `slots` vs `children`
370+
371+
You may wonder why we need both `slots` and `children`. Wouldn't `slots().default` be the same as `children`? In some cases, yes - but what if you have a functional component with the following children?
372+
373+
``` html
374+
<my-functional-component>
375+
<p slot="foo">
376+
first
377+
</p>
378+
<p>second</p>
379+
</my-functional-component>
380+
```
381+
382+
For this component, `children()` will give you both paragraphs, `slots().default` will give you only the second, and `slots().foo` will give you only the first. Having both `children` and `slots` therefore allows you to choose whether this component knows about a slot system or perhaps delegates that responsibility to another component by simply passing along `children`.
383+
369384
## Misc
370385

371386
### `keep-alive`

0 commit comments

Comments
 (0)