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
Copy file name to clipboardExpand all lines: source/guide/components.md
+10-4Lines changed: 10 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -209,9 +209,9 @@ The two-way binding will sync the change of child's `msg` property back to the p
209
209
210
210
<pclass="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>
211
211
212
-
### Prop Validation
212
+
### Prop Specification
213
213
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:
215
215
216
216
```js
217
217
Vue.component('example', {
@@ -228,6 +228,14 @@ Vue.component('example', {
228
228
type:Number,
229
229
default:100
230
230
},
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
+
},
231
239
// a two-way prop. will throw warning if binding type
232
240
// does not match.
233
241
twoWayProp: {
@@ -256,8 +264,6 @@ In addition, `type` can also be a custom constructor function and the the assert
256
264
257
265
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.
258
266
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
-
261
267
### Inheriting Parent Scope
262
268
263
269
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