1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <script setup> // 数组语法(简单声明) const props = defineProps(['title', 'content', 'count'])
// 对象语法(带类型验证与默认值) const detailProps = defineProps({ title: { type: String, required: true, default: '默认标题' }, count: { type: Number, default: 0, validator: (value) => value >= 0 }, status: { type: String, default: 'pending', validator: (value) => ['pending', 'success', 'error'].includes(value) } }) </script>
<template> <div> <h1>{{ detailProps.title }}</h1> <p>计数: {{ detailProps.count }}</p> </div> </template>
|