vuejs-challenges
vuejs-challenges copied to clipboard
323 - Prop Validation
<script lang="ts" setup>
import { PropType } from 'vue';
type ButtonType = 'primary' | 'ghost' | 'dashed' | 'text' | 'default';
const props = defineProps({
type: {
type: String as PropType<ButtonType>,
default: 'default',
validator: (value) => {
return ['primary', 'ghost', 'dashed', 'text', 'default'].includes(value);
},
},
});
</script>
<template>
<button :type="props.type">Button</button>
</template>