vue3+ts 父子组件通讯1(definePrpps、defineEmits)
1.父组件
<Son v-model:dialogVisiblec="dialogTableVisible" :title="title" @callBack="callBack" />
2.子组件
<script lang="ts" setup> import { ref, watch } from 'vue' const emit = defineEmits(['callBack']) const props = defineProps({ title: { type: String, required: true }, dialogVisible: { type: Boolean } }) emit('callBack', value) </script>
3.v-bind值传入 definePrpps取值、v-on对v-ondefineEmits往回传的值进行处理。definePrpps、defineEmits都是只在setup语法糖中使用的编译器宏,不需要导入,会随着<script setup>的处理过程一起处理掉,defineProps 是一个方法,内部返回一个对象(所有挂载到该组件的props,不指定prop的属性值会放入attrs中

浙公网安备 33010602011771号