微信小程序如何在循环之中使用 slot
发布于 4 年前 作者 laiping 5206 次浏览 来自 分享

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>

最终效果:

以上。

回到顶部