如何解决从孩子更改插槽道具
在 Vue JS 中,如何将一个组件作为另一个组件的 prop(或插槽)传递,同时能够从孙组件设置它自己的 props?
家长:
y
孩子:
<template>
<Child>
<SomeComponent />
</Child>
</template>
孙子:
<template>
<GrandChild>
<slot></slot>
</GrandChild>
</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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。