Skip to content

Commit 5ae11ca

Browse files
committed
updates for 2.3.0
1 parent 0f1da8f commit 5ae11ca

File tree

4 files changed

+74
-5
lines changed

4 files changed

+74
-5
lines changed

src/v2/api/index.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ type: api
122122
```html
123123
<input type="text" @keyup.media-play-pause="method">
124124
```
125-
125+
126126
Define custom key alias(es) for v-on.
127127

128128
### performance
@@ -1670,9 +1670,10 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
16701670
- `.{keyCode | keyAlias}` - only trigger handler on certain keys.
16711671
- `.native` - listen for a native event on the root element of component.
16721672
- `.once` - trigger handler at most once.
1673-
- `.left` - (2.2.0) only trigger handler for left button mouse events.
1674-
- `.right` - (2.2.0) only trigger handler for right button mouse events.
1675-
- `.middle` - (2.2.0) only trigger handler for middle button mouse events.
1673+
- `.left` - (2.2.0+) only trigger handler for left button mouse events.
1674+
- `.right` - (2.2.0+) only trigger handler for right button mouse events.
1675+
- `.middle` - (2.2.0+) only trigger handler for middle button mouse events.
1676+
- `.passive` - (2.3.0+) attaches a DOM event with `{ passive: true }`.
16761677

16771678
- **Usage:**
16781679

@@ -1742,7 +1743,8 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
17421743

17431744
- **Modifiers:**
17441745
- `.prop` - Bind as a DOM property instead of an attribute. ([what's the difference?](http://stackoverflow.com/questions/6003819/properties-and-attributes-in-html#answer-6004028))
1745-
- `.camel` - transform the kebab-case attribute name into camelCase. (supported since 2.1.0)
1746+
- `.camel` - (2.1.0+) transform the kebab-case attribute name into camelCase.
1747+
- `.sync` - (2.3.0+) a syntax sugar that expands into a `v-on` handler for updating the bound value.
17461748
17471749
- **Usage:**
17481750
@@ -1802,6 +1804,7 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
18021804
- **See also:**
18031805
- [Class and Style Bindings](../guide/class-and-style.html)
18041806
- [Components - Component Props](../guide/components.html#Props)
1807+
- [Components - `.sync` Modifier](../guide/components.html#sync-Modifier)
18051808
18061809
### v-model
18071810

src/v2/guide/class-and-style.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,13 @@ The array syntax for `v-bind:style` allows you to apply multiple style objects t
192192
### Auto-prefixing
193193

194194
When you use a CSS property that requires [vendor prefixes](https://developer.mozilla.org/en-US/docs/Glossary/Vendor_Prefix) in `v-bind:style`, for example `transform`, Vue will automatically detect and add appropriate prefixes to the applied styles.
195+
196+
### Multiple Values
197+
198+
> 2.3.0+
199+
200+
Starting in 2.3 you can provide an array of multiple (prefixed) values to a style property, for example:
201+
202+
``` html
203+
<div :style="{ display: ["-webkit-box", "-ms-flexbox", "flex"] }">
204+
```

src/v2/guide/components.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,34 @@ There may be times when you want to listen for a native event on the root elemen
534534
<my-component v-on:click.native="doTheThing"></my-component>
535535
```
536536

537+
### `.sync` Modifier
538+
539+
> 2.3.0+
540+
541+
In some cases we may need "two-way binding" for a prop - in fact, in Vue 1.x this is exactly what the `.sync` modifier provided. When a child component mutates a prop that has `.sync`, the value change will be reflected in the parent. This is convenient, however it leads to maintenance issues in the long run because it breaks the one-way data flow assumption: the code that mutates child props are implicitly affecting parent state.
542+
543+
This is why we removed the `.sync` modifier when 2.0 was released. However, we've found that there are indeed cases where it could be useful, especially when shipping reusable components. What we need to change is **making the code in the child that affects parent state more consistent and explicit.**
544+
545+
In 2.3 we re-introduced the `.sync` modifier for props, but this time it is just syntax sugar that automatically expands into an additional `v-on` listener:
546+
547+
The following
548+
549+
``` html
550+
<comp :foo.sync="bar"></comp>
551+
```
552+
553+
is expanded into:
554+
555+
``` html
556+
<comp :foo="bar" @update:foo="val => bar = val"></comp>
557+
```
558+
559+
For the child component to update `foo`'s value, it needs to explicitly emit an event instead of mutating the prop:
560+
561+
``` js
562+
this.$emit('update:foo', newValue)
563+
```
564+
537565
### Form Input Components using Custom Events
538566

539567
Custom events can also be used to create custom inputs that work with `v-model`. Remember:
@@ -1063,6 +1091,30 @@ new Vue({
10631091

10641092
<p class="tip">If you're a <strong>Browserify</strong> user that would like to use async components, its creator has unfortunately [made it clear](https://github.com/substack/node-browserify/issues/58#issuecomment-21978224) that async loading "is not something that Browserify will ever support." Officially, at least. The Browserify community has found [some workarounds](https://github.com/vuejs/vuejs.org/issues/620), which may be helpful for existing and complex applications. For all other scenarios, we recommend simply using Webpack for built-in, first-class async support.</p>
10651093

1094+
### Advanced Async Components
1095+
1096+
> New in 2.3.0
1097+
1098+
Starting in 2.3 the async component factory can also return an object of the following format:
1099+
1100+
``` js
1101+
const AsyncComp = () => ({
1102+
// The component to load. Should be a Promise
1103+
component: import('./MyComp.vue'),
1104+
// A component to use while the async component is loading
1105+
loading: LoadingComp,
1106+
// A component to use if the load fails
1107+
error: ErrorComp,
1108+
// Delay before showing the loading component. Default: 200ms.
1109+
delay: 200,
1110+
// The error component will be displayed if a timeout is
1111+
// provided and exceeded. Default: Infinity.
1112+
timeout: 3000
1113+
})
1114+
```
1115+
1116+
Note that when used as a route component in `vue-router`, these properties will be ignored because async components are resolved upfront before the route navigation happens. You also need to use `vue-router` 2.4.0+ if you wish to use the above syntax for route components.
1117+
10661118
### Component Naming Conventions
10671119

10681120
When registering components (or props), you can use kebab-case, camelCase, or TitleCase. Vue doesn't care.

src/v2/guide/render-function.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,17 @@ Vue.component('my-component', {
468468
})
469469
```
470470

471+
> Note: in versions <=2.3.0, the `props` option is required if you wish to accept props in a functional component. In 2.3.0+ you can omit the `props` option and all attributes found on the component node will be implicitly extracted as props.
472+
471473
Everything the component needs is passed through `context`, which is an object containing:
472474

473475
- `props`: An object of the provided props
474476
- `children`: An array of the VNode children
475477
- `slots`: A function returning a slots object
476478
- `data`: The entire data object passed to the component
477479
- `parent`: A reference to the parent component
480+
- `listeners`: (2.3.0+) An object containing parent-registered event listeners. This is simply an alias to `data.on`
481+
- `injections`: (2.3.0+) if using the [`inject`](https://vuejs.org/v2/api/#provide-inject) option, this will contain resolved injections.
478482

479483
After adding `functional: true`, updating the render function of our anchored heading component would simply require adding the `context` argument, updating `this.$slots.default` to `context.children`, then updating `this.level` to `context.props.level`.
480484

0 commit comments

Comments
 (0)