[英]passing vue slot in child component
Is there a possibility to access the Vue slot in a deeper nested child component like this?有没有可能像这样在更深的嵌套子组件中访问 Vue 插槽?
<Parent>
<Child1>
<Child2>
Content
</Child2>
</Child1>
</Parent>
I want to pass HTML to a deeper child component from the parent component.我想将 HTML 从父组件传递给更深的子组件。
using scoped slots we can iterate over the slots and pass them down使用作用域插槽,我们可以遍历插槽并将它们向下传递
notice the child-slot
name;注意
child-slot
名称;
# Parent
<template>
<Child1>
<template v-slot:child-slot>
Content
</template>
</Child1>
</template>
# Child 1
<template>
<Child2>
<template v-for="(index, name) in $scopedSlots" v-slot:[name]="data">
<slot :name="name" v-bind="data"></slot>
</template>
</Child2>
</template>
# Child 2
<template>
<div>
<slot name="child-slot">Fallback Content</slot>
</div>
</template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.