vue3 setup特性 子父组件传值
<script setup>
import { ref, defineEmits, defineProps } from 'vue'
/* 子组件接收值 */
const Props = defineProps({
ArrData: {
type: Array
}
})
//使用方式 div直接使用 ArrData.xxx
let x = Props.ArrData //必须这样初始化
/* 传值父组件 */
const emits = defineEmits(['PutSchool'])
//使用方式
emits("PutSchool",{ //给父组件传值
key:1,
id: id.value,
});
// 接收放方式
// 在子组件上 @PutSchool="PutSchool"
</script>
父组件触发子组件函数
//子组件暴露函数
defineExpose({
funcShow
});
//父组件
<ImgModal ref="refsImgModal" />
let refsImgModal = ref(null)
const clickImage = (index, url) => {
refsImgModal.value.funcShow()
}