<script setup lang="ts">
// ts写法
const props = withDefaults(defineProps<{
title?: string // 是否必传
}>(),{
title:'默认值'
})
// 非ts写法
const props = defineProps({
title: {
type: String,
default: '默认值',
required: false // 是否必传
}
})
// 使用 props
const useProps = () => {
console.log(props.title) // 默认值
}
</script>
vue3给props设置默认值【defineProps】
于 2022-03-30 11:14:57 首次发布