component.js:
Component({
properties: {
thing: Object
},
options: {
multipleSlots: true
}
})
component.wxml:
<block
wx:for="{{thing}}"
wx:for-item="t"
wx:for-index="i"
>
<view>Heading: {{t}}</view>
<slot name="slot-{{i}}" />
</block>
index.js:
Page({
data: {
// ...
someArray: [1, 2, 233]
}
})
index.wxml:
<test-component thing="{{someArray}}">
<view wx:for="{{someArray}}" wx:for-index="i" slot="{{i}}">test</view>
</test-component>
最终效果:
以上。
换思路可以使用抽象节点完成你想要的
https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/generics.html
https://developers.weixin.qq.com/community/develop/article/doc/000488097e8410da5b792c7f35ec13
抽象节点相当于只能使用一个插槽点
这个方法不行的,插入的内容,不在循环的元素当中