9.slot插槽组件

2023-10-24  本文已影响0人  LucXion
应用场景

子组件中某一个位置的组件由 父视图填充

// 使用步骤
// 1. 子组件 .js 中打开插槽功能
    options: {
        multipleSlots: true
    },

// 2. 子组件 .wxml 中,设置slot的名称和位置
<slot name="header"> </slot>
<view wx:for="{{list}}" wx:key="index">{{item.title}}</view>
<slot name="footer"> </slot>

// 3. 父组件 .wxml 中,在子组件内添加需要的组件,通过设置组件的 slot名称,来实现填充
    <list tag = "{{titleindex}}">
    <view slot = "header">这就是头部</view>
    </list>
上一篇 下一篇

猜你喜欢

热点阅读