17
18export default defineComponent({
19 name: "BasicButton",
20 props: ["to"],21 setup() {
22 return {
23 notNull,
In committed code, prop definitions should always be as detailed as possible, specifying at least type(s).
Detailed prop definitions have two advantages:
They document the API of the component, so that it's easy to see how the component is meant to be used.
In development, Vue will warn you if a component is ever provided incorrectly formatted props, helping you catch potential sources of error.
<script>
Vue.component('bar', {
props: ['foo']
})
Vue.component('baz', {
props: {
foo: {},
}
})
</script>
<script>
Vue.component('foo', {
props: {
// Without options, just type reference
foo: String,
// With options with type field
bar: {
type: String,
required: true,
},
// With options without type field but with validator field
baz: {
required: true,
validator: function (value) {
return (
value === null ||
Array.isArray(value) && value.length > 0
)
}
}
}
})
</script>