Skip to content

Commit 3e5e52e

Browse files
authored
docs: shallow unwrap on setup (#851)
1 parent cb38a49 commit 3e5e52e

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/guide/composition-api-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ If `setup` returns an object, the properties on the object can be accessed in th
142142
</script>
143143
```
144144

145-
Note that [refs](../api/refs-api.html#ref) returned from `setup` are [automatically unwrapped](/guide/reactivity-fundamentals.html#ref-unwrapping) when accessed in the template so you shouldn't use `.value` in templates.
145+
Note that [refs](../api/refs-api.html#ref) returned from `setup` are [automatically shallow unwrapped](/guide/reactivity-fundamentals.html#ref-unwrapping) when accessed in the template so you shouldn't use `.value` in templates.
146146

147147
## Usage with Render Functions
148148

src/guide/reactivity-fundamentals.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ console.log(count.value) // 1
4545

4646
### Ref Unwrapping
4747

48-
When a ref is returned as a property on the render context (the object returned from [setup()](composition-api-setup.html)) and accessed in the template, it automatically unwraps to the inner value. There is no need to append `.value` in the template:
48+
When a ref is returned as a property on the render context (the object returned from [setup()](composition-api-setup.html)) and accessed in the template, it automatically shallow unwraps the inner value. Only the nested ref will require `.value` in the template:
4949

5050
```vue-html
5151
<template>
5252
<div>
5353
<span>{{ count }}</span>
5454
<button @click="count ++">Increment count</button>
55+
<button @click="nested.count.value ++">Nested Increment count</button>
5556
</div>
5657
</template>
5758
@@ -61,13 +62,27 @@ When a ref is returned as a property on the render context (the object returned
6162
setup() {
6263
const count = ref(0)
6364
return {
64-
count
65+
count,
66+
67+
nested: {
68+
count
69+
}
6570
}
6671
}
6772
}
6873
</script>
6974
```
7075

76+
::tip
77+
If you don't need to access the actual object instance, you can wrap it in a reactive:
78+
79+
```js
80+
rested: reactive({
81+
count
82+
})
83+
```
84+
::
85+
7186
### Access in Reactive Objects
7287

7388
When a `ref` is accessed or mutated as a property of a reactive object, it automatically unwraps to the inner value so it behaves like a normal property:

0 commit comments

Comments
 (0)