You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1670,9 +1670,10 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
1670
1670
-`.{keyCode | keyAlias}`- only trigger handler on certain keys.
1671
1671
-`.native`- listen for a native event on the root element of component.
1672
1672
-`.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 DOMeventwith`{ passive: true }`.
1676
1677
1677
1678
-**Usage:**
1678
1679
@@ -1742,7 +1743,8 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
1742
1743
1743
1744
-**Modifiers:**
1744
1745
-`.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.
1746
1748
1747
1749
- **Usage:**
1748
1750
@@ -1802,6 +1804,7 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
1802
1804
- **See also:**
1803
1805
- [Class and Style Bindings](../guide/class-and-style.html)
Copy file name to clipboardExpand all lines: src/v2/guide/class-and-style.md
+10Lines changed: 10 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -192,3 +192,13 @@ The array syntax for `v-bind:style` allows you to apply multiple style objects t
192
192
### Auto-prefixing
193
193
194
194
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:
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
+
537
565
### Form Input Components using Custom Events
538
566
539
567
Custom events can also be used to create custom inputs that work with `v-model`. Remember:
@@ -1063,6 +1091,30 @@ new Vue({
1063
1091
1064
1092
<pclass="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>
1065
1093
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
+
constAsyncComp= () => ({
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
+
1066
1118
### Component Naming Conventions
1067
1119
1068
1120
When registering components (or props), you can use kebab-case, camelCase, or TitleCase. Vue doesn't care.
> 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
+
471
473
Everything the component needs is passed through `context`, which is an object containing:
472
474
473
475
-`props`: An object of the provided props
474
476
-`children`: An array of the VNode children
475
477
-`slots`: A function returning a slots object
476
478
-`data`: The entire data object passed to the component
477
479
-`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.
478
482
479
483
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`.
0 commit comments