Vue.js: Specify multiple types for component props
August 4, 2022 ‐ 1 min read
Vue doesn't enforce a specific type for the component props you define. Even if you specify a property to be of type Number
you can potentially still pass a string. It's up to you. It does, however, spawn some useful console warnings in development.
In some cases your component might accept multiple prop types. We can specify which ones by using an array containing the accepted types. As is shown in the following example.
<script>
export default {
props: {
value: {
type: [String, Number],
required: true
}
}
}
</script>