Reputation: 2860
I know I can give any prop its expected type and default value like this:
export default {
name: "myComponent",
props: {
myProp: { type: String, default: 'any text' }
}
}
And I so in documentation I can give 2 types as array like this:
export default {
name: "myComponent",
props: {
myProp: [String, Array]
}
}
BUT I would expect I can also give any of these types a default value also (this is not working): Is it possible?
export default {
name: "myComponent",
props: {
myProp: **[{type: String, default: ''}, {type: Array, default: []} ]**
}
}
Upvotes: 0
Views: 2712
Reputation: 22393
I think it's impossible, for example if you have
export default {
name: "myComponent",
props: {
myProp: [
{type: String, default: ''},
{type: Array, default: []}
]
}
}
then when you write your component without passing myProp
:
<my-component />
Then my-component
doesn't know it should take value from default String
or default Array
definition.
Upvotes: 2