Skip to content

Commit 7e96c96

Browse files
committed
feedback for reactivity fundamentals
1 parent 2c61266 commit 7e96c96

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/guide/essentials/reactivity-fundamentals.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ function mutateDeeply() {
240240

241241
</div>
242242

243-
It is also possible to explicitly create [shallow refs](/api/reactivity-advanced.html#shallowref) and [shallow reactive objects](/api/reactivity-advanced.html#shallowreactive) where the reactivity is only tracked at the root-level, however they are typically only needed in advanced use cases.
243+
It is also possible to explicitly create [shallow reactive objects](/api/reactivity-advanced.html#shallowreactive) where the reactivity is only tracked at the root-level, however they are typically only needed in advanced use cases.
244244

245245
<div class="composition-api">
246246

@@ -364,7 +364,7 @@ In other words, `ref()` allows us to create a "reference" to any value and pass
364364

365365
### Ref Unwrapping in Templates \*\*
366366

367-
When refs are exposed to templates and accessed on the render context, they are automatically "unwrapped" so there is no need to use `.value`. Here's the previous counter example, using `ref()` instead:
367+
When refs are accessed as top-level properties in the template, they are automatically "unwrapped" so there is no need to use `.value`. Here's the previous counter example, using `ref()` instead:
368368

369369
```vue{13}
370370
<script setup>
@@ -386,6 +386,28 @@ function increment() {
386386

387387
[Try it in the Playground](https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHNjcmlwdCBzZXR1cD5cbmltcG9ydCB7IHJlZiB9IGZyb20gJ3Z1ZSdcblxuY29uc3QgY291bnQgPSByZWYoMClcblxuZnVuY3Rpb24gaW5jcmVtZW50KCkge1xuICBjb3VudC52YWx1ZSsrXG59XG48L3NjcmlwdD5cblxuPHRlbXBsYXRlPlxuICA8YnV0dG9uIEBjbGljaz1cImluY3JlbWVudFwiPnt7IGNvdW50IH19PC9idXR0b24+XG48L3RlbXBsYXRlPiIsImltcG9ydC1tYXAuanNvbiI6IntcbiAgXCJpbXBvcnRzXCI6IHtcbiAgICBcInZ1ZVwiOiBcImh0dHBzOi8vc2ZjLnZ1ZWpzLm9yZy92dWUucnVudGltZS5lc20tYnJvd3Nlci5qc1wiXG4gIH1cbn0ifQ==)
388388

389+
Note the unwrapping only applies to top-level properties - nested access to refs will not be unwrapped:
390+
391+
```js
392+
const object = { foo: ref(1) }
393+
```
394+
395+
```vue-html
396+
{{ object.foo }} <!-- does NOT get unwrapped -->
397+
```
398+
399+
We can fix that by making `foo` a top-level property:
400+
401+
```js
402+
const { foo } = object
403+
```
404+
405+
```vue-html
406+
{{ foo }} <!-- properly unwrapped -->
407+
```
408+
409+
Now `foo` will be wrapped as expected.
410+
389411
### Ref Unwrapping in Reactive Objects \*\*
390412

391413
When a `ref` is accessed or mutated as a property of a reactive object, it is also automatically unwrapped so it behaves like a normal property:

0 commit comments

Comments
 (0)