Validate enum prop in vue
It's very common to validate prop as enum:
<script>
const VALID_TYPES = ['primary', 'secondary', 'warning']
const VALID_SIZES = ['mini', 'small', 'semi-wide', 'wide']
export default {
props: {
type: {
type: [String, Array],
default: 'primary',
validator: type => VALID_TYPES.includes(type),
},
size: {
type: String,
default: 'small',
validator: size => VALID_SIZES.includes(size)
},
},
}
</script>
What happens if default
is not provided (and is not required
)