1. 父传子数据 props
父组件:
往子组件中传入数据
<child1 :count="count"></child1>
const count = ref(100)
子组件:
defineProps接收父组件给的数据
defineProps(["count"]);
2. 子传父数据 props
父组件:
往子组件传入回调函数
<child2 :count="count" @my-event="handleMyEvent"></child2>
const handleMyEvent = (titleFromSon) => {
fatherGetTitle.value = titleFromSon.value;
};
子组件:
defineEmits 接收父组件的回调函数
const emit = define