自定义组件内的遍历block能放slot吗
发布于 5 年前 作者 jie36 11447 次浏览 来自 问答
  • 需求的场景描述(希望解决的问题)

自定义组件:商品列表。     引用页面写好slot然后应用在每个商品卡片上

  • 希望提供的能力

列表组件,类似商品表。希望能沟通过block遍历让传过来的slot应用在所有商品卡片上。

component.wxml

<view>

<scroll-view

   scroll-x="{{datagridData.scrollX}}"

   scroll-y="{{datagridData.scrollY}}"

   upper-threshold="{{datagridData.upperThreshold}}"

   lower-threshold="{{datagridData.lowerThreshold}}"

   scroll-top="{{datagridData.scrollTop}}"

   scroll-left="{{datagridData.scrollLeft}}"

   scroll-into-view="{{datagridData.scrollIntoView}}"

   scroll-with-animation="{{datagridData.scrollWithAnimation}}"

   enable-back-to-top="{{datagridData.enableBackToTop}}"

   bindscrolltoupper="{{datagridData.bindscrolltoupper}}"

   bindscrolltolower="{{datagridData.bindscrolltolower}}"

   bindscroll="{{datagridData.bindscroll}}"

   aria-label="{{datagridData.ariaLabel}}"

   style="{{datagridData.style}}"

>

 

   <block wx:for="{{datagridData.valueData}}" wx:key="{{index}}" >

 

       <view style="{{datagridData.itemStyle}}">

       <!-- 传入slot (有没有图片,有没有标题,有没有文字介绍,有没有按钮,都能通过slot传到卡片上)–>

       <slot></slot>

       </view>

   </block>

</scroll-view>

</view>

我的问题是,slot只在被第一张卡片应用,之后就好像消失了。是不是在block里被用过一次就失效了?

1 回复
回到顶部