Reputation: 2651
I have props with defined types but I want the last one of them to accept any kind of value
props: {
Size: String,
Label: String,
Name: String,
value: Any
}
Hpw can I achieve this?
Upvotes: 50
Views: 44923
Reputation:
From VueJS docs:
null
andundefined
values will pass any type validation
Or you can use array and place in it all required types:
propB: [String, Number]
Upvotes: 94
Reputation: 5855
To support props type any
when you have props with defined types:
props: {
custom1: null, // set as `null`
custom2: undefined, // or `undefined`
// if you need to add extra rules, simply don't set the `type` prop
custom3: {
required: true,
//... rest of your props
}
}
DEMO: https://jsfiddle.net/xa91zoyq/4/
Upvotes: 4
Reputation: 3226
Here is what I'm doing to pass lint validation.
You could of corse do real validation here.
There are many handy methods that lodash provides for checking types
value: {
required: true,
validator: v => true
},
Upvotes: 0