Skip to content

Commit 07a9bd4

Browse files
committed
clarify behavior for Vue.observable
1 parent 3945e1d commit 07a9bd4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/v2/api/index.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ type: api
8282

8383
> In 2.2.0+, this hook also captures errors in component lifecycle hooks. Also, when this hook is `undefined`, captured errors will be logged with `console.error` instead of crashing the app.
8484
85-
> In 2.4.0+ this hook also captures errors thrown inside Vue custom event handlers.
85+
> In 2.4.0+, this hook also captures errors thrown inside Vue custom event handlers.
8686
87-
> In 2.6.0+ this hook also captures errors thrown inside `v-on` DOM listeners. In addition, if any of the covered hooks or handlers returns a Promise chain (e.g. async functions), the error from that Promise chain will also be handled.
87+
> In 2.6.0+, this hook also captures errors thrown inside `v-on` DOM listeners. In addition, if any of the covered hooks or handlers returns a Promise chain (e.g. async functions), the error from that Promise chain will also be handled.
8888
8989
> Error tracking services [Sentry](https://sentry.io/for/vue/) and [Bugsnag](https://docs.bugsnag.com/platforms/browsers/vue/) provide official integrations using this option.
9090
@@ -404,31 +404,33 @@ type: api
404404

405405
- **See also:** [Render Functions](../guide/render-function.html)
406406

407-
### Vue.observable( value )
407+
### Vue.observable( object )
408408

409409
> New in 2.6.0+
410410
411411
- **Arguments:**
412-
- `{Object} value`
412+
- `{Object} object`
413413

414414
- **Usage:**
415415

416-
Explicitly creates a reactive object. This is what Vue performs internally on objects returned from a component's `data()` function.
416+
Make an object reactive. Internally, Vue uses this on the object returned by the `data` function.
417417

418-
The returned object can be used directly inside [render functions](../guide/render-function.html) and [computed properties](../guide/computed.html), and will trigger appropriate updates when mutated. It can be used as a minimal cross-component state store for simple scenarios.
418+
The returned object can be used directly inside [render functions](../guide/render-function.html) and [computed properties](../guide/computed.html), and will trigger appropriate updates when mutated. It can also be used as a minimal, cross-component state store for simple scenarios:
419419

420420
``` js
421-
const obj = Vue.observable({ count: 0 })
421+
const state = Vue.observable({ count: 0 })
422422

423423
const Demo = {
424424
render(h) {
425425
return h('button', {
426-
on: { click: () => { obj.count++ }}
427-
}, `count is: ${obj.count}`)
426+
on: { click: () => { state.count++ }}
427+
}, `count is: ${state.count}`)
428428
}
429429
}
430430
```
431431

432+
<p class="tip">In Vue 2.x, `Vue.observable` directly mutates the object passed to it, so that it is equivalent to the object returned, as [demonstrated here](../guide/instance.html#Data-and-Methods). In Vue 3.x, a reactive proxy will be returned instead, leaving the original object non-reactive if mutated directly. Therefore, for future compatibility, we recommend always working with the object returned by `Vue.observable`, rather than the object originally passed to it.</p>
433+
432434
- **See also:** [Reactivity in Depth](../guide/reactivity.html)
433435

434436
### Vue.version

0 commit comments

Comments
 (0)