vue3 setup特性 子父组件传值

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()
}
360 Views
分享你的喜爱
linwute
linwute

我要像梦一样自由,像大地一样宽容;
在艰辛放逐的路上,点亮生命的光芒;
我要像梦一样自由,像天空一样坚强;
在曲折蜿蜒的路上,体验生命的意义;

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注