vue 插槽 slot 传值给父元素,在引入组件的位置获取插槽传递的参数

1. 插槽组件:在 slot 标签上绑定属性,作为 slot参数传递出去

<template>
	<div>
		<div class="slot-template">
			<slot :data="list"></slot>
		</div>
	</div>
</template>

<script>
export default {
	data() {
		return {
			list: [12, 23, 34],
		};
	},
};
</script>

2. 使用 组件插槽的父组件:使用v-slot 接收 子组件传递过来的参数,并通过该参数得到 slot 传递过来的值。

<template>
	<div class="father-components">
		<SlotComponent v-slot="slotProps">
			{{ slotProps.data }}
		</SlotComponent>
	</div>
</template>

<script>
import SlotComponent from "@/components/SlotComponent";

export default {
	components: { SlotComponent },
};
</script>

posted @   柯宝宝智商感人  阅读(1316)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示