Skip to content

Commit 9d52084

Browse files
committed
useAttrs, useSlots, useModel
1 parent e3d9fc6 commit 9d52084

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/api/composition-api-helpers.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,39 @@
22

33
## useAttrs() {#useattrs}
44

5+
Returns the `attrs` object from the [Setup Context](/api/composition-api-setup#setup-context), which includes the [fallthrough attributes](/guide/components/attrs#fallthrough-attributes) of the current component. This is intended to be used in `<script setup>` where the setup context object is not available.
6+
57
## useSlots() {#useslots}
68

9+
Returns the `slots` object from the [Setup Context](/api/composition-api-setup#setup-context), which includes parent passed slots as callable functions that return Virtual DOM nodes. This is intended to be used in `<script setup>` where the setup context object is not available.
10+
11+
If using TypeScript, [`defineSlots()`](/api/sfc-script-setup#defineslots) should be preferred instead.
12+
713
## useModel() <sup class="vt-badge" data-text="3.4+" /> {#usemodel}
814

15+
This is the underlying helper that powers [`defineModel()`](/api/sfc-script-setup#definemodel). If using `<script setup>`, `defineModel()` should be preferred instead.
16+
17+
`useModel()` can be used in non-SFC components, e.g. when using raw `setup()` function. It expects the `props` object as the first argument, and the model name as the second argument. The optional third argument can be used to declare custom getter and setter for the resulting model ref. Note that unlike `defineModel()`, you are responsible for declaring the props and emits yourself.
18+
19+
- **Example**
20+
21+
```js
22+
export default {
23+
props: ['count'],
24+
emits: ['update:count'],
25+
setup(props) {
26+
const msg = useModel(props, 'count')
27+
msg.value = 1
28+
}
29+
}
30+
```
31+
932
## useTemplateRef() <sup class="vt-badge" data-text="3.5+" /> {#usetemplateref}
1033

1134
## useId() <sup class="vt-badge" data-text="3.5+" /> {#useid}
1235

1336
`useId()` is an API that can be used to generate unique-per-application IDs.
1437

15-
- **Composition API only.**
16-
1738
- **Example**
1839

1940
```vue

0 commit comments

Comments
 (0)