typescript - Làm thế nào để định nghĩa giá trị mặc định cho props trong Vue 3?
Làm thế nào để tôi định nghĩa giá trị mặc định của một prop trong script setup của Vue 3?
interface InputProps {
message: string
error?: string
}
const props = defineProps<InputProps>()
Câu trả lời #1
Thêm một giá trị mặc định bằng cách sử dụng withDefaults trong Vue 3 Composition API:
interface InputProps {
message: string
error?: string
}
const props = withDefaults(defineProps<InputProps>(), {
message: null
})
tìm hiểu thêm ở đây
