Skip to content

Commit e3d9fc6

Browse files
committed
3.5: add composition api helpers page
1 parent 9bc11b2 commit e3d9fc6

File tree

3 files changed

+44
-31
lines changed

3 files changed

+44
-31
lines changed

.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ export const sidebar: ThemeConfig['sidebar'] = {
368368
{
369369
text: 'Dependency Injection',
370370
link: '/api/composition-api-dependency-injection'
371+
},
372+
{
373+
text: 'Helpers',
374+
link: '/api/composition-api-helpers'
371375
}
372376
]
373377
},

src/api/composition-api-helpers.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Composition API: Helpers {#composition-api-helpers}
2+
3+
## useAttrs() {#useattrs}
4+
5+
## useSlots() {#useslots}
6+
7+
## useModel() <sup class="vt-badge" data-text="3.4+" /> {#usemodel}
8+
9+
## useTemplateRef() <sup class="vt-badge" data-text="3.5+" /> {#usetemplateref}
10+
11+
## useId() <sup class="vt-badge" data-text="3.5+" /> {#useid}
12+
13+
`useId()` is an API that can be used to generate unique-per-application IDs.
14+
15+
- **Composition API only.**
16+
17+
- **Example**
18+
19+
```vue
20+
<script setup>
21+
import { useId } from 'vue'
22+
23+
const id = useId()
24+
</script>
25+
26+
<template>
27+
<form>
28+
<label :for="id">Name:</label>
29+
<input :id="id" type="text" />
30+
</form>
31+
</template>
32+
```
33+
34+
- **Details**
35+
36+
IDs generated by `useId()` are unique-per-application. It can be used to generate IDs for form elements and accessibility attributes. Multiple calls in the same component will generate different IDs; multiple instances of the same component calling `useId()` will also have different IDs.
37+
38+
IDs generated by `useId()` are also guaranteed to be stable across the server and client renders, so they can be used in SSR applications without leading to hydration mismatches.
39+
40+
If you have more than one Vue application instance of the same page, you can avoid ID conflicts by giving each app an ID prefix via [`app.config.idPrefix`](/api/application#app-config-idprefix).

src/api/general.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -266,34 +266,3 @@ This method accepts the same argument as [`defineComponent`](#definecomponent),
266266
- [Guide - Building Custom Elements with Vue](/guide/extras/web-components#building-custom-elements-with-vue)
267267
268268
- Also note that `defineCustomElement()` requires [special config](/guide/extras/web-components#sfc-as-custom-element) when used with Single-File Components.
269-
270-
## useId() <sup class="vt-badge" data-text="3.5+" /> {#useid}
271-
272-
`useId()` is an API that can be used to generate unique-per-application IDs.
273-
274-
- **Composition API only.**
275-
276-
- **Example**
277-
278-
```vue
279-
<script setup>
280-
import { useId } from 'vue'
281-
282-
const id = useId()
283-
</script>
284-
285-
<template>
286-
<form>
287-
<label :for="id">Name:</label>
288-
<input :id="id" type="text" />
289-
</form>
290-
</template>
291-
```
292-
293-
- **Details**
294-
295-
IDs generated by `useId()` are unique-per-application. It can be used to generate IDs for form elements and accessibility attributes. Multiple calls in the same component will generate different IDs; multiple instances of the same component calling `useId()` will also have different IDs.
296-
297-
IDs generated by `useId()` are also guaranteed to be stable across the server and client renders, so they can be used in SSR applications without leading to hydration mismatches.
298-
299-
If you have more than one Vue application instance of the same page, you can avoid ID conflicts by giving each app an ID prefix via [`app.config.idPrefix`](/api/application#app-config-idprefix).

0 commit comments

Comments
 (0)