问题
按文档中的interface
和PropType
定义数据,2者没有对应上,为什么没有错误提示,如果这样也能检查通过,哪么加入interface
和PropType
的意义是什么
文档
代码
interface
interface Book {
title: string
author: string
year: number
}
父组件的数据
const state = reactive({
book: {
author: 'string',
year: 10,
aa: 'aa'
}
})
子组件接收数据
export default defineComponent({
props: {
book: {
type: Object as PropType<Book>,
required: true,
}
},
setup (props) {
onMounted(() => {
console.log('book', props.book)
})
return {}
}
})