Skip to content

Commit 3cd3e69

Browse files
authored
Merge pull request #1939 from vuejs/2.6
[In Review] 2.6 Updates
2 parents 5e1911b + f39e3e0 commit 3cd3e69

File tree

5 files changed

+603
-104
lines changed

5 files changed

+603
-104
lines changed

src/v2/api/index.md

Lines changed: 141 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +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.
86+
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.
8688
8789
> Error tracking services [Sentry](https://sentry.io/for/vue/) and [Bugsnag](https://docs.bugsnag.com/platforms/browsers/vue/) provide official integrations using this option.
8890
@@ -402,6 +404,35 @@ type: api
402404

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

407+
### Vue.observable( object )
408+
409+
> New in 2.6.0+
410+
411+
- **Arguments:**
412+
- `{Object} object`
413+
414+
- **Usage:**
415+
416+
Make an object reactive. Internally, Vue uses this on the object returned by the `data` function.
417+
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:
419+
420+
``` js
421+
const state = Vue.observable({ count: 0 })
422+
423+
const Demo = {
424+
render(h) {
425+
return h('button', {
426+
on: { click: () => { state.count++ }}
427+
}, `count is: ${state.count}`)
428+
}
429+
}
430+
```
431+
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+
434+
- **See also:** [Reactivity in Depth](../guide/reactivity.html)
435+
405436
### Vue.version
406437

407438
- **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
13911422
13921423
> New in 2.1.0+
13931424
1394-
- **Type:** `{ [name: string]: props => VNode | Array<VNode> }`
1425+
- **Type:** `{ [name: string]: props => Array<VNode> | undefined }`
13951426
13961427
- **Read only**
13971428
@@ -1401,6 +1432,12 @@ type: api
14011432
14021433
Accessing `vm.$scopedSlots` is most useful when writing a component with a [render function](../guide/render-function.html).
14031434
1435+
**Note:** since 2.6.0+, there are two notable changes to this property:
1436+
1437+
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`.
1438+
1439+
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.
1440+
14041441
- **See also:**
14051442
- [`<slot>` Component](#slot-1)
14061443
- [Scoped Slots](../guide/components.html#Scoped-Slots)
@@ -1948,7 +1985,7 @@ type: api
19481985
19491986
### v-for
19501987
1951-
- **Expects:** `Array | Object | number | string`
1988+
- **Expects:** `Array | Object | number | string | Iterable (since 2.6)`
19521989
19531990
- **Usage:**
19541991
@@ -1976,6 +2013,8 @@ type: api
19762013
</div>
19772014
```
19782015

2016+
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.
2017+
19792018
<p class="tip">When used together with v-if, v-for has a higher priority than v-if. See the <a href="../guide/list.html#v-for-with-v-if">list rendering guide</a> for details.</p>
19802019

19812020
The detailed usage for `v-for` is explained in the guide section linked below.
@@ -2021,12 +2060,18 @@ type: api
20212060
<!-- method handler -->
20222061
<button v-on:click="doThis"></button>
20232062
2063+
<!-- dynamic event (2.6.0+) -->
2064+
<button v-on:[event]="doThis"></button>
2065+
20242066
<!-- inline statement -->
20252067
<button v-on:click="doThat('hello', $event)"></button>
20262068
20272069
<!-- shorthand -->
20282070
<button @click="doThis"></button>
20292071
2072+
<!-- shorthand dynamic event (2.6.0+) -->
2073+
<button @[event]="doThis"></button>
2074+
20302075
<!-- stop propagation -->
20312076
<button @click.stop="doThis"></button>
20322077
@@ -2097,9 +2142,15 @@ type: api
20972142
<!-- bind an attribute -->
20982143
<img v-bind:src="imageSrc">
20992144
2145+
<!-- dynamic attribute name (2.6.0+) -->
2146+
<button v-bind:[key]="value"></button>
2147+
21002148
<!-- shorthand -->
21012149
<img :src="imageSrc">
21022150
2151+
<!-- shorthand dynamic attribute name (2.6.0+) -->
2152+
<button :[key]="value"></button>
2153+
21032154
<!-- with inline string concatenation -->
21042155
<img :src="'/path/to/images/' + fileName">
21052156
@@ -2164,6 +2215,59 @@ type: api
21642215
- [Form Input Bindings](../guide/forms.html)
21652216
- [Components - Form Input Components using Custom Events](../guide/components.html#Form-Input-Components-using-Custom-Events)
21662217

2218+
### v-slot
2219+
2220+
- **Shorthand:** `#`
2221+
2222+
- **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.
2223+
2224+
- **Argument:** slot name (optional, defaults to `default`)
2225+
2226+
- **Limited to:**
2227+
- `<template>`
2228+
- [components](../guide/components-slots.html#Abbreviated-Syntax-for-Lone-Default-Slots) (for a lone default slot with props)
2229+
2230+
- **Usage:**
2231+
2232+
Denote named slots or slots that expect to receive props.
2233+
2234+
- **Example:**
2235+
2236+
```html
2237+
<!-- Named slots -->
2238+
<base-layout>
2239+
<template v-slot:header>
2240+
Header content
2241+
</template>
2242+
2243+
Default slot content
2244+
2245+
<template v-slot:footer>
2246+
Footer content
2247+
</template>
2248+
</base-layout>
2249+
2250+
<!-- Named slot that receives props -->
2251+
<infinite-scroll>
2252+
<template v-slot:item="slotProps">
2253+
<div class="item">
2254+
{{ slotProps.item.text }}
2255+
</div>
2256+
</template>
2257+
</infinite-scroll>
2258+
2259+
<!-- Default slot that receive props, with destructuring -->
2260+
<mouse-position v-slot="{ x, y }">
2261+
Mouse position: {{ x }}, {{ y }}
2262+
</mouse-position>
2263+
```
2264+
2265+
For more details, see the links below.
2266+
2267+
- **See also:**
2268+
- [Components - Slots](../guide/components-slots.html)
2269+
- [RFC-0001](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0001-new-slot-syntax.md)
2270+
21672271
### v-pre
21682272
21692273
- **Does not expect expression**
@@ -2283,38 +2387,6 @@ type: api
22832387
22842388
- **See also:** [Child Component Refs](../guide/components.html#Child-Component-Refs)
22852389
2286-
### slot
2287-
2288-
- **Expects:** `string`
2289-
2290-
Used on content inserted into child components to indicate which named slot the content belongs to.
2291-
2292-
For detailed usage, see the guide section linked below.
2293-
2294-
- **See also:** [Named Slots](../guide/components.html#Named-Slots)
2295-
2296-
### slot-scope
2297-
2298-
> New in 2.5.0+
2299-
2300-
- **Expects:** `function argument expression`
2301-
2302-
- **Usage:**
2303-
2304-
Used to denote an element or component as a scoped slot. The attribute's value should be a valid JavaScript expression that can appear in the argument position of a function signature. This means in supported environments you can also use ES2015 destructuring in the expression. Serves as a replacement for [`scope`](#scope-replaced) in 2.5.0+.
2305-
2306-
This attribute does not support dynamic binding.
2307-
2308-
- **See also:** [Scoped Slots](../guide/components.html#Scoped-Slots)
2309-
2310-
### scope <sup>replaced</sup>
2311-
2312-
Used to denote a `<template>` element as a scoped slot, which is replaced by [`slot-scope`](#slot-scope) in 2.5.0+.
2313-
2314-
- **Usage:**
2315-
2316-
Same as [`slot-scope`](#slot-scope) except that `scope` can only be used on `<template>` elements.
2317-
23182390
### is
23192391
23202392
- **Expects:** `string | Object (component’s options object)`
@@ -2340,6 +2412,40 @@ Used to denote a `<template>` element as a scoped slot, which is replaced by [`s
23402412
- [Dynamic Components](../guide/components.html#Dynamic-Components)
23412413
- [DOM Template Parsing Caveats](../guide/components.html#DOM-Template-Parsing-Caveats)
23422414
2415+
### slot <sup style="color:#c92222">deprecated</sup>
2416+
2417+
**Prefer [v-slot](#v-slot) in 2.6.0+.**
2418+
2419+
- **Expects:** `string`
2420+
2421+
Used on content inserted into child components to indicate which named slot the content belongs to.
2422+
2423+
- **See also:** [Named Slots with `slot`](../guide/components.html#Named-Slots-with-slot)
2424+
2425+
### slot-scope <sup style="color:#c92222">deprecated</sup>
2426+
2427+
**Prefer [v-slot](#v-slot) in 2.6.0+.**
2428+
2429+
- **Expects:** `function argument expression`
2430+
2431+
- **Usage:**
2432+
2433+
Used to denote an element or component as a scoped slot. The attribute's value should be a valid JavaScript expression that can appear in the argument position of a function signature. This means in supported environments you can also use ES2015 destructuring in the expression. Serves as a replacement for [`scope`](#scope-replaced) in 2.5.0+.
2434+
2435+
This attribute does not support dynamic binding.
2436+
2437+
- **See also:** [Scoped Slots with `slot-scope`](../guide/components.html#Scoped-Slots-with-slot-scope)
2438+
2439+
### scope <sup style="color:#c92222">removed</sup>
2440+
2441+
**Replaced by [slot-scope](#slot-scope) in 2.5.0+. Prefer [v-slot](#v-slot) in 2.6.0+.**
2442+
2443+
Used to denote a `<template>` element as a scoped slot.
2444+
2445+
- **Usage:**
2446+
2447+
Same as [`slot-scope`](#slot-scope) except that `scope` can only be used on `<template>` elements.
2448+
23432449
## Built-In Components
23442450

23452451
### component

0 commit comments

Comments
 (0)