vue3给props设置默认值【defineProps】
vue3.2 defineProps设置默认值
文章共277字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
<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>
更多推荐
已为社区贡献1条内容
所有评论(0)