This repository was archived by the owner on Aug 8, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 1
1
## 模板引用
2
2
3
- > 本节使用 [ 单文件组件] ( single-file-component.html ) 代码示例的语法
3
+ > 本节代码示例使用 [ 单文件组件] ( single-file-component.html ) 的语法
4
4
5
- > 本指南假定你已经阅读了 [ Composition API 简介] ( composition-api-introduction.html ) 和[ 响应式基础] ( reactivity-fundamentals.html ) 。如果你不熟悉组合 API,请先阅读这篇文章 。
5
+ > 本指南假定你已经阅读了 [ Composition API 简介] ( composition-api-introduction.html ) 和[ 响应式基础] ( reactivity-fundamentals.html ) 。如果你不熟悉组合 API,请先阅读此文章 。
6
6
7
7
在使用组合 API 时,[ 响应式引用] ( reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs ) 和[ 模板引用] ( component-template-refs.html ) 的概念是统一的。为了获得对模板内元素或组件实例的引用,我们可以像往常一样声明 ref 并从 [ setup ()] ( composition-api-setup.html ) 返回:
8
8
9
9
``` html
10
- <template >
10
+ <template >
11
11
<div ref =" root" >This is a root element</div >
12
12
</template >
13
13
31
31
</script >
32
32
```
33
33
34
- 这里我们在渲染上下文中暴露 ` root ` ,并通过 ` ref="root" ` ,将其绑定到 div 作为其 ref。在虚拟 DOM 修补算法中 ,如果 VNode 的 ` ref ` 键对应于渲染上下文中的 ref,则 VNode 的相应元素或组件实例将被分配给该 ref 的值。这是在虚拟 DOM 挂载/打补丁过程中执行的,因此模板引用只会在初始渲染之后获得赋值。
34
+ 这里我们在渲染上下文中暴露 ` root ` ,并通过 ` ref="root" ` ,将其绑定到 div 作为其 ref。在虚拟 DOM 补丁算法中 ,如果 VNode 的 ` ref ` 键对应于渲染上下文中的 ref,则 VNode 的相应元素或组件实例将被分配给该 ref 的值。这是在虚拟 DOM 挂载/打补丁过程中执行的,因此模板引用只会在初始渲染之后获得赋值。
35
35
36
- 作为模板使用的 ref 的行为与任何其他 ref 一样:它们是响应式的,可以传递到 (或从) 复合函数中返回 。
36
+ 作为模板使用的 ref 的行为与任何其他 ref 一样:它们是响应式的,可以传递到 (或从中返回) 复合函数中 。
37
37
38
- ### JSX的用法
38
+ ### JSX 中的用法
39
39
40
40
``` js
41
41
export default {
@@ -53,7 +53,7 @@ export default {
53
53
}
54
54
```
55
55
56
- ### 内部使用 ` v-for `
56
+ ### ` v-for ` 中的用法
57
57
58
58
Composition API 模板引用在 ` v-for ` 内部使用时没有特殊处理。相反,请使用函数引用执行自定义处理:
59
59
You can’t perform that action at this time.
0 commit comments