Skip to content

Commit a1fdbf1

Browse files
committed
props with object default
1 parent 67e1634 commit a1fdbf1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

source/guide/components.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ The two-way binding will sync the change of child's `msg` property back to the p
209209

210210
<p class="tip">Note that if the prop being passed down is an Object or an Array, it is passed by reference. Mutating the Object or Array itself inside the child will affect parent state, regardless of the binding type you are using.</p>
211211

212-
### Prop Validation
212+
### Prop Specification
213213

214-
It is possible for a component to validate the props it is receiving. This is useful when you are authoring a component that is intended to be used by others, as these prop validation requirements essentially constitute your component's API, and ensure your users are using your component correctly. Instead of defining the props as strings, you can use Objects that contain validation requirements:
214+
It is possible for a component to specify the requirements for the props it is receiving. This is useful when you are authoring a component that is intended to be used by others, as these prop validation requirements essentially constitute your component's API, and ensure your users are using your component correctly. Instead of defining the props as strings, you can use Objects that contain validation requirements:
215215

216216
``` js
217217
Vue.component('example', {
@@ -228,6 +228,14 @@ Vue.component('example', {
228228
type: Number,
229229
default: 100
230230
},
231+
// object/array defaults should be returned from a
232+
// factory function
233+
propWithObjectDefault: {
234+
type: Object,
235+
default: function () {
236+
return { msg: 'hello' }
237+
}
238+
},
231239
// a two-way prop. will throw warning if binding type
232240
// does not match.
233241
twoWayProp: {
@@ -256,8 +264,6 @@ In addition, `type` can also be a custom constructor function and the the assert
256264

257265
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.
258266

259-
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.
260-
261267
### Inheriting Parent Scope
262268

263269
If you want, you can also use the `inherit: true` option for your child component to make it prototypally inherit all parent properties:

0 commit comments

Comments
 (0)