评论

微信小程序如何在循环之中使用 slot

微信小程序如何在循环之中使用 slot?

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>

最终效果:

以上。

最后一次编辑于  2019-11-11  
点赞 2
收藏
评论

3 个评论

登录 后发表内容