Skip to content

Commit d8dc723

Browse files
heappyndJustineo
andauthored
docs: translate composition-api-helpers (#1011)
Co-authored-by: GU Yiling <[email protected]>
1 parent 06892d5 commit d8dc723

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/api/composition-api-helpers.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
<!-- TODO: translation -->
2-
# Composition API: Helpers {#composition-api-helpers}
1+
# 组合式 API:辅助 {#composition-api-helpers}
32

43
## useAttrs() {#useattrs}
54

6-
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.
5+
[Setup 上下文](/api/composition-api-setup#setup-context) 中返回 `attrs` 对象,其中包含当前组件的[透传 attributes](/guide/components/attrs#fallthrough-attributes)。这是用于 `<script setup>` 中的,因为在 `<script setup>` 中无法获取 setup 上下文对象的。
76

8-
- **Type**
7+
- **类型**
98

109
```ts
1110
function useAttrs(): Record<string, unknown>
1211
```
1312

1413
## useSlots() {#useslots}
1514

16-
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.
15+
[Setup 上下文](/api/composition-api-setup#setup-context) 中返回 `slots` 对象,其中包含父组件传递的插槽。这些插槽为可调用的函数,返回虚拟 DOM 节点。这是用于 `<script setup>` 中的,因为在 `<script setup>` 中无法获取 setup 上下文对象的。
1716

18-
If using TypeScript, [`defineSlots()`](/api/sfc-script-setup#defineslots) should be preferred instead.
17+
如果使用 TypeScript,建议优先使用 [`defineSlots()`](/api/sfc-script-setup#defineslots)
1918

20-
- **Type**
19+
- **类型**
2120

2221
```ts
2322
function useSlots(): Record<string, (...args: any[]) => VNode[]>
2423
```
2524

2625
## useModel() {#usemodel}
2726

28-
This is the underlying helper that powers [`defineModel()`](/api/sfc-script-setup#definemodel). If using `<script setup>`, `defineModel()` should be preferred instead.
27+
这是驱动 [`defineModel()`](/api/sfc-script-setup#definemodel) 的底层辅助函数。如果使用 `<script setup>`,应当优先使用 `defineModel()`
2928

30-
- Only available in 3.4+
29+
- 仅在 3.4+ 版本中可用
3130

32-
- **Type**
31+
- **类型**
3332

3433
```ts
3534
function useModel(
@@ -44,7 +43,7 @@ This is the underlying helper that powers [`defineModel()`](/api/sfc-script-setu
4443
}
4544
```
4645

47-
- **Example**
46+
- **示例**
4847

4948
```js
5049
export default {
@@ -57,21 +56,21 @@ This is the underlying helper that powers [`defineModel()`](/api/sfc-script-setu
5756
}
5857
```
5958

60-
- **Details**
59+
- **详细信息**
6160

62-
`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.
61+
`useModel()` 可以用于非 SFC 组件,例如在使用原始的 `setup()` 函数时。它预期的第一个参数是 `props` 对象,第二个参数是 model 名称。可选的第三个参数可以用于为生成的 model ref 声明自定义的 getter setter。请注意,与 `defineModel()` 不同,你需要自己声明 props emits
6362

6463
## useTemplateRef() <sup class="vt-badge" data-text="3.5+" /> {#usetemplateref}
6564

66-
Returns a shallow ref whose value will be synced with the template element or component with a matching ref attribute.
65+
返回一个浅层 ref,其值将与模板中的具有匹配 ref attribute 的元素或组件同步。
6766

68-
- **Type**
67+
- **类型**
6968

7069
```ts
7170
function useTemplateRef<T>(key: string): Readonly<ShallowRef<T | null>>
7271
```
7372

74-
- **Example**
73+
- **示例**
7574

7675
```vue
7776
<script setup>
@@ -89,22 +88,22 @@ Returns a shallow ref whose value will be synced with the template element or co
8988
</template>
9089
```
9190

92-
- **See also**
93-
- [Guide - Template Refs](/guide/essentials/template-refs)
94-
- [Guide - Typing Template Refs](/guide/typescript/composition-api#typing-template-refs) <sup class="vt-badge ts" />
95-
- [Guide - Typing Component Template Refs](/guide/typescript/composition-api#typing-component-template-refs) <sup class="vt-badge ts" />
91+
- **参考**
92+
- [指南 - 模板引用](/guide/essentials/template-refs)
93+
- [指南 - 为模板引用标注类型](/guide/typescript/composition-api#typing-template-refs) <sup class="vt-badge ts" />
94+
- [指南 - 为组件模板引用标注类型](/guide/typescript/composition-api#typing-component-template-refs) <sup class="vt-badge ts" />
9695

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

99-
Used to generate unique-per-application IDs for accessibility attributes or form elements.
98+
用于为无障碍属性或表单元素生成每个应用内唯一的 ID
10099

101-
- **Type**
100+
- **类型**
102101

103102
```ts
104103
function useId(): string
105104
```
106105

107-
- **Example**
106+
- **示例**
108107

109108
```vue
110109
<script setup>
@@ -121,10 +120,10 @@ Used to generate unique-per-application IDs for accessibility attributes or form
121120
</template>
122121
```
123122

124-
- **Details**
123+
- **详细信息**
125124

126-
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.
125+
`useId()` 生成的每个 ID 在每个应用内都是唯一的。它可以用于为表单元素和无障碍属性生成 ID。在同一个组件中多次调用会生成不同的 ID;同一个组件的多个实例调用 `useId()` 也会生成不同的 ID
127126

128-
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.
127+
`useId()` 生成的 ID 在服务器端和客户端渲染之间是稳定的,因此可以安全地在 SSR 应用中使用,不会导致激活不匹配。
129128

130-
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).
129+
如果同一页面上有多个 Vue 应用实例,可以通过 [`app.config.idPrefix`](/api/application#app-config-idprefix) 为每个应用提供一个 ID 前缀,以避免 ID 冲突。

0 commit comments

Comments
 (0)