小程序自定义组件slot的使用

小程序自定义组件slot的使用

在自定义的组件中使用插槽slot

自定义组件

<view class="contant">
    <view class="title-box">标题1</view>
    <slot class="contant-box" name="自定义名字" >
        
    </slot>
</view>

要使用该组件的页面

<!-- 卡片 -->
<cards>   // 自定义组件的名称
    <view slot="对应slot 的name">
    </view>
</cards> 

在这里插入图片描述

slot 里面的name是一一对应的

使用多个slot卡槽

自定义组件

<view class="contant">
    <view class="title-box">标题1</view>
    <slot class="contant-box" name="box1"></slot>
    <slot class="contant-box" name="box2"></slot>
</view>

使用组件的文件

<cards>
    <view slot="box2">插入组件里面的东西2</view>
    <view slot="box1">插入组件里面的东1</view>
</cards>
顺序是颠倒的,那我们一起看看结果吧

在这里插入图片描述

最后是按照自定义组件那边来区分排序的

小编自己在学习小程序开发过程中,自己做了个UI组件库,方便一下自己,大家可以参考一下

https://github.com/qq894617385/congUI.git

猜你喜欢

转载自blog.csdn.net/weixin_43285211/article/details/84070559