diff --git a/src/v2/api/index.md b/src/v2/api/index.md index 77fb63baf3..292b598393 100644 --- a/src/v2/api/index.md +++ b/src/v2/api/index.md @@ -82,7 +82,9 @@ type: api > 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. - > In 2.4.0+ this hook also captures errors thrown inside Vue custom event handlers. + > In 2.4.0+, this hook also captures errors thrown inside Vue custom event handlers. + + > 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. > Error tracking services [Sentry](https://sentry.io/for/vue/) and [Bugsnag](https://docs.bugsnag.com/platforms/browsers/vue/) provide official integrations using this option. @@ -402,6 +404,35 @@ type: api - **See also:** [Render Functions](../guide/render-function.html) +### Vue.observable( object ) + +> New in 2.6.0+ + +- **Arguments:** + - `{Object} object` + +- **Usage:** + + Make an object reactive. Internally, Vue uses this on the object returned by the `data` function. + + 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: + + ``` js + const state = Vue.observable({ count: 0 }) + + const Demo = { + render(h) { + return h('button', { + on: { click: () => { state.count++ }} + }, `count is: ${state.count}`) + } + } + ``` + +

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.

+ +- **See also:** [Reactivity in Depth](../guide/reactivity.html) + ### Vue.version - **Details**: Provides the installed version of Vue as a string. This is especially useful for community plugins and components, where you might use different strategies for different versions. @@ -1391,7 +1422,7 @@ type: api > New in 2.1.0+ -- **Type:** `{ [name: string]: props => VNode | Array }` +- **Type:** `{ [name: string]: props => Array | undefined }` - **Read only** @@ -1401,6 +1432,12 @@ type: api Accessing `vm.$scopedSlots` is most useful when writing a component with a [render function](../guide/render-function.html). + **Note:** since 2.6.0+, there are two notable changes to this property: + + 1. Scoped slot functions are now guaranteed to return an array of VNodes, unless the return value is invalid, in which case the function will return `undefined`. + + 2. All `$slots` are now also exposed on `$scopedSlots` as functions. If you work with render functions, it is now recommended to always access slots via `$scopedSlots`, whether they currently use a scope or not. This will not only make future refactors to add a scope simpler, but also ease your eventual migration to Vue 3, where all slots will be functions. + - **See also:** - [`` Component](#slot-1) - [Scoped Slots](../guide/components.html#Scoped-Slots) @@ -1948,7 +1985,7 @@ type: api ### v-for -- **Expects:** `Array | Object | number | string` +- **Expects:** `Array | Object | number | string | Iterable (since 2.6)` - **Usage:** @@ -1976,6 +2013,8 @@ type: api ``` + In 2.6+, `v-for` can also work on values that implement the [Iterable Protocol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol), including native `Map` and `Set`. However, it should be noted that Vue 2.x currently does not support reactivity on `Map` and `Set` values, so cannot automatically detect changes. +

When used together with v-if, v-for has a higher priority than v-if. See the list rendering guide for details.

The detailed usage for `v-for` is explained in the guide section linked below. @@ -2021,12 +2060,18 @@ type: api + + + + + + @@ -2097,9 +2142,15 @@ type: api + + + + + + @@ -2164,6 +2215,59 @@ type: api - [Form Input Bindings](../guide/forms.html) - [Components - Form Input Components using Custom Events](../guide/components.html#Form-Input-Components-using-Custom-Events) +### v-slot + +- **Shorthand:** `#` + +- **Expects:** JavaScript expression that is valid in a function argument position (supports destructuring in [supported environments](../guide/components-slots.html#Slot-Props-Destructuring)). Optional - only needed if expecting props to be passed to the slot. + +- **Argument:** slot name (optional, defaults to `default`) + +- **Limited to:** + - `