v2.2.0 Initial D
"Fill'er up. High Octane."
This release contains 31 pull requests from 22 different contributors - thank you!
Upgrade Note
- In addition to
vue
, make sure to also upgradevue-template-compiler
andvue-loader
.
Notable Changes
There are no breaking changes to the public API in this release. However, some internal changes may require adjustments on your part if your code relies on some undocumented behavior in previous versions.
-
When using
v-for
with a component, akey
is now required. You will likely see a bunch of "soft warnings" when you upgrade, but this does not affect the current behavior of your app. -
The template parser will now raise errors for tags that are missing matching closing tags. Although a tag without matching closing tag is vaild in HTML5, it is most of the time an unintentional mistake, and can lead to subtle bugs. This check does not work for in-DOM templates because the HTML string is already normalized by the browser before being passed to Vue's parser.
-
Props and computed properties are now defined on a component's prototype instead of as self properties on each instance. This avoids many calls to
Object.defineProperty
and improves component initialization performance. This will only affect you if you rely onhasOwnProperty
checks on props and computed properties, which should be extremely rare, but we are documenting it here to be explicit about the change. (relevant commits: 406352b, e870e6c) -
If you previously relied on
try...catch
for handling possible errors in component lifecycle hooks, the errors will no longer be thrown directly. However, you can use the globalVue.config.errorHandler
to intercept and handle those errors. -
Many exposed methods and properties on
Vue.util
have been removed. If you previously relied on them, you should migrate off of them since this object is intended for internal use only - it is not (and has never been) considered part of the public API and may change without notice in the future. -
The default export used by Webpack 2 will now point to an ES module build (
dist/vue.runtime.esm.js
). This means without any alias configuration,require('vue')
in webpack 2 will give you an object ({ __esModule: true, default: Vue }
) instead. You should only useimport Vue from 'vue'
with webpack 2.Also see updated dist files information for more details.
For TypeScript + webpack 2 users: the new default ES module export will no longer work with
import Vue = require('vue')
- please see updated TypeScript integration docs for more details.
New
Server-Side Rendering Improvements
- New renderer option:
template
. Allows passing in a template for the entire HTML page. Docs bundleRenderer
now accepts a special bundle object generated by vue-ssr-webpack-plugin. Using the new bundle format seamlessly supports webpack code splitting and source maps. Docs- There are also related improvements in
vue-router
andvue-style-loader
which together makes SSR + code splitting very straightforward - stay tuned for a detailed writeup.
Error Handling Improvements
-
Errors thrown in component lifecycle hooks and watcher getter/callbacks no longer crash the entire app. These errors are now also forwarded to
Vue.config.errorHandler
, if provided. -
New option:
renderError
. A separate render function that will be used when there's an error in the default render function. Receives the error as the second argument.new Vue({ render (h) { throw new Error('oops') }, renderError (h, err) { return h('pre', { style: { color: 'red' }}, err.stack) } }).$mount('#app')
Component v-model
Customization
-
Previously,
v-model
on a custom component defaults to usevalue
as the prop andinput
as the event. This places some restrictions when authoring custom input components that resembles checkboxes or radio inputs. In 2.2 you can customize the props/event pair using the newmodel
component option:Vue.component('my-checkbox', { model: { prop: 'checked', event: 'change' }, props: { // this allows using the `value` prop for a different purpose value: String }, // ... })
<my-checkbox v-model="foo" value="some value"></my-checkbox>
The above will be equivalent to:
<my-checkbox :checked="foo" @change="(val) => { foo = val }" value="some value"> </my-checkbox>
Provide & Inject
-
The new
provide
andinject
options provide similar functionality to React's context feature:const Provider = { provide () { return { foo: 'bar' } } } const Consumer = { inject: ['foo'] }
Now as long as
Consumer
is instantiated in the descendant tree ofProvider
, it will getfoo
injected into it (this.foo === 'bar'
). This is a feature mostly intended for advanced usage by plugin / component library authors and should be used with caution.Special thanks to the discussion in #4029 and the community implementation (https://github.com/spatie/vue-expose-inject).
Other Improvements
-
The production mode tip on startup can now be turned off by setting
Vue.config.productionTip = false
. -
A component's current props are now also exposed on
this.$props
. (@yantene via #4848) -
<transition>
and<transition-group>
now accepts explicit transition durations via the newduration
prop: (@Akryum via #4857)<!-- same duration for enter/leave --> <transition :duration="500"> <!-- different duration for enter/leave --> <transition :duration="{ enter: 300, leave: 500 }">
-
New config:
Vue.config.performance
. Setting it to true traces component init, compile, render and patch time in the browser devtool timeline. Only available in dev mode. -
<keep-alive>
:activated
anddeactivated
now fires for all components inside an activated/deactivated tree. -
vm.$on()
now supports registering the same callback for multiple events usingvm.$on([eventA, eventB], callback)
(@Kingwl via #4860) -
v-on
new mouse event modifiers:.left
,.right
,.middle
. Example:<button @click.right="onRightClick">
(@Kingwl via #4866) -
vue-template-compiler
:parseComponent
result now also includes the attrs for each block. (@zephraph via #4925) -
Vue.delete
now also supports Arrays:Vue.delete(arr, index)
(@Hanks10100 via #4747)
Fixed
- #4749 (keep-alive) handle invalid include/exclude values [458671b]
- #4753 (parser) fix infinite loop when parsing elements that contains
<
only (@dhcmrlchtdj via #4753) [938fa4e] - #4755 (v-model) handle dynamic
<select multiple>
bindings (@defcc via #4756) [9e38abc] - #4758 (parser) preserve only whitespace child in
<pre>
tags (@defcc via #4760) [e02fb12] - #4767 (core) ensure mutating extended constructor options does not affect parent [769c4dc]
- #4774 (core) fix replaced component root nodes losing parent scopeId [90a455c]
- #4779 (slots) fix scoped slots with dynamic slot names [e7083d0]
- #4796, #4896 (v-model) fix
v-model
+@change
behavior inconsistency in different browsers [8e854a9] - #4797 (parser) avoid double-decoding on attribute value (@jddxf via #4797) [d14bd64]
- #4813 (parser) fix SVG
foreignObject
regression (@zephraph via #4926) [0201d8c] - #4838 (filter) fix filter parsing error for division operator (@rixlabs via #4844) [7259aef]
- #4846 (v-on) fix .once with other modifiers that prevent execution of a handler [05c769b]
- #4855 (v-model) fix
<select multiple>
binding with undefined value (@posva via #4859) [ec7fca8] - #4863 (transition) trim transition class whitespace (@hashplus via #4863) [8bf5af8]
- #4872 (core) fix props default value factory function when running application code in different realm (@HerringtonDarkholme via #4928) [01151ce]
- #4900 (transition) fix transition-group move transition detection [6977109]
- #4936 (ssr) bundleRenderer should resolve
require()
calls relative to bundle location. [8d88512] - #4950 (core) warn when defining a method with same name as a prop (@chriscasola via #4950) [3dc9338]
- #4976 (core) properly handle cosntructor options modification before global mixin [4cf4982, 7fa8fa7]
- #4985 (transition) fix transition appear class fallback [7d3309d]
- #4990 (core) fix memory leak in directives with
componentUpdated
hook [2a5fb41] - vuejs/vue-loader#628 (parser) fix parser hanging on trailing ill-formatted brackets [a0a619f]