0.12.1
Breaking Changes
It is unfortunate that I have to make a breaking change right after the 0.12 release, but I believe this is a necessary change before users have already invested in the new API.
-
Prop Binding Types have been redesigned.
-
All prop bindings are now one-way-down by default. This means parent changes are synced to the child but not the other way around. This default is meant to prevent child components from accidentally mutating the parent's state, which can make your app's data flow harder to reason about.
-
You can still explicitly create a two way binding with the new syntax:
<component prop="{{@ twoWayBound }}"></component>
-
One-way-up binding type has been removed.
-
One-time binding remains the same using the
prop="{{* oneTime }}"
syntax.
-
New Features
-
Prop Validation
You can now optionally define a prop as an object that contains additional validation requirements:
Vue.component('example', { props: [ { name: 'on-something', type: Function }, { name: 'required-prop', required: true }, { name: 'greater-than-ten', // custom validator function validator: function (value) { return value > 10 } } ] })
The
type
can be one of the following native constructors:- String
- Number
- Boolean
- Function
- Object
- Array
In addition,
type
can also be a custom constructor function and the the assertion will be made with aninstanceof
check.When a prop validation fails, Vue will refuse the set the value on the child component, and throw a warning if using the development build.
You can still use strings if your props don't need any validation, and you can mix string and object props in the option array.