[英]Change slot props from child
在 Vue JS 中,如何将组件作为另一个组件的 prop(或插槽)传递,同时能够从孙组件设置它自己的 props?
家长:
<template>
<Child>
<SomeComponent />
</Child>
</template>
孩子 :
<template>
<GrandChild>
<slot></slot>
</GrandChild>
</template>
孙子:
<template>
<slot :content="content"></slot> //Setting the props of <SomeComponent/> here
</template>
使用“v-slot:default”!
家长:
<template>
<Child>
<template v-slot:default="slotProps">
<SomeComponent :content="slotProps.content"/>
</template>
</Child>
</template>
孩子 :
<template>
<GrandChild>
<template v-slot:default="slotProps">
<slot :content="slotProps.content"></slot>
</template>
</GrandChild>
</template>
孙子:
<template>
<slot :content="content"></slot>
</template>
我建议您参考此文档。
https://v3.vuejs.org/guide/component-slots.html#scoped-slots
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.