Skip to content

Commit 0a3f144

Browse files
authored
docs: add explanation for scoped slots with render functions (#2670)
1 parent 209f6a2 commit 0a3f144

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/guide/extras/render-function.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,41 @@ JSX equivalent:
577577

578578
Passing slots as functions allows them to be invoked lazily by the child component. This leads to the slot's dependencies being tracked by the child instead of the parent, which results in more accurate and efficient updates.
579579

580+
### Scoped Slots
581+
582+
To render a scoped slot in the parent component, a slot is passed to the child. Notice how the slot now has a parameter `text`. The slot will be called in the child component and the data from the child component will be passed up to the parent component.
583+
584+
```js
585+
// parent component
586+
export default {
587+
setup() {
588+
return () => h(MyComp, null, {
589+
default: ({ text }) => h('p', text)
590+
})
591+
}
592+
}
593+
```
594+
595+
Remember to pass `null` so the slots will not be treated as props.
596+
597+
```js
598+
// child component
599+
export default {
600+
setup(props, { slots }) {
601+
const text = ref('hi')
602+
return () => h('div', null, slots.default({ text: text.value }))
603+
}
604+
}
605+
```
606+
607+
JSX equivalent:
608+
609+
```jsx
610+
<MyComponent>{{
611+
default: ({ text }) => <p>{ text }</p>
612+
}}</MyComponent>
613+
```
614+
580615
### Built-in Components {#built-in-components}
581616

582617
[Built-in components](/api/built-in-components) such as `<KeepAlive>`, `<Transition>`, `<TransitionGroup>`, `<Teleport>` and `<Suspense>` must be imported for use in render functions:

0 commit comments

Comments
 (0)