2.4 组件间通信Props(父传子)
父组件
在父组件模板上的子组件上加上属性值,属性值就是想要传递给子组件的信息。
例如:
<template>
<div class="Big-box"><testBox :personList="p"></testBox>
</div>
</template>
子组件
子组件接收父子间传递的信息
const x = defineProps(['personList'])
子组件接收规范的父子间传递的信息
const x = defineProps<{personList:Person}>()
子组件接收规范的父子间传递的可选的非必要信息
const x = defineProps<{personList?:Person}>()
子组件接收规范的父子间传递的可选的非必要信息,有默认值
const x = withDefaults(defineProps<{personList?:Person}>(),{...
})