Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2e14787

Browse files
committedOct 12, 2021
总结ref
1 parent d246901 commit 2e14787

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,16 @@ npm run dev
111111
- 但在setup中<strong style="color:#DD5145">不能访问到</strong>Vue2.x配置(data、methos、computed...)。
112112
- 如果有重名, setup优先。
113113
2. setup不能是一个async函数,因为返回值不再是return的对象, 而是promise, 模板看不到return对象中的属性。(后期也可以返回一个Promise实例,但需要Suspense和异步组件的配合)
114+
115+
116+
## 2.ref函数
117+
118+
- 作用: 定义一个响应式的数据
119+
- 语法: ```const xxx = ref(initValue)```
120+
- 创建一个包含响应式数据的<strong style="color:#DD5145">引用对象(reference对象,简称ref对象)</strong>。
121+
- JS中操作数据: ```xxx.value```
122+
- 模板中读取数据: 不需要.value,直接:```<div>{{xxx}}</div>```
123+
- 备注:
124+
- 接收的数据可以是:基本类型、也可以是对象类型。
125+
- 基本类型的数据:响应式依然是靠``Object.defineProperty()`````get``````set```完成的。
126+
- 对象类型的数据:内部 <i style="color:gray;font-weight:bold">“ 求助 ”</i> 了Vue3.0中的一个新函数—— ```reactive```函数。

0 commit comments

Comments
 (0)
Please sign in to comment.