简体   繁体   English

在 Vue.js 中为子组件中的迭代槽迭代槽内容

[英]Iterating slot content for iterated slots in child component in Vue.js

I've got a child component (that I cannot edit) where each row in an object is rendered inside a div with a specific slot, and I'd need to pass data from the parent for each of those elements.我有一个子组件(我无法编辑),其中对象中的每一行都在具有特定插槽的 div 内呈现,并且我需要为每个元素传递来自父级的数据。 I'm trying to iterate through every element of the object in the parent component, generate a slot and pass the desired code to the child, but unfortunately I can't manage to and I can't find any material to support me.我试图遍历父组件中对象的每个元素,生成一个插槽并将所需的代码传递给子组件,但不幸的是我无法做到,也找不到任何材料来支持我。

The child component:子组件:

<div class="slotchildren" v-for="(child, childindex) in row.elementChildren" :key="childindex">

  <span>element nr. {{child.id}}</span>
  <slot :name="`element-child-${row[idlabel]}-${childindex}`" :row="child">
    ...
  </slot>
</div>

The parent component (not working):父组件(不工作):

<template v-for="row in rows"> -->
  <template  v-slot:`element-row-${row.id}`="{row}">
        
        //--> [vue/valid-v-slot] 'v-slot' directive doesn't support any modifier
        //--> [vue/valid-v-slot] 'v-slot' directive must be owned by a custom element, but 'template' is not.

    <span>{{row.name}}</span>

  </template>
</template>

Is something like this feasible and how?这样的事情可行吗? If it's not, what could be a viable workaround, consideind that I can't edit the child component?如果不是,那么可行的解决方法是什么,考虑到我无法编辑子组件?

Thanks in advance.提前致谢。

I solved it with the following synthax:我用以下合成器解决了它:

<template v-for="row in rows" v-slot:[`element-row-${row.id}`]>
  ..
</template> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM