微信小程序瀑布流组件

先在component中创建一个waterfull的文件夹,并创建对应的wxml,wxss,jx,json文件

wxml

html 复制代码
    <view class="content">
    <view class="content-left">
        <block wx:for="{{list}}" wx:key="list" wx:if="{{index % 2 == 0}}">
            <view class="content-item" bindtap="detail" data-v="{{item}}">
                <image src="{{item.image}}" class="content-item-img" mode="widthFix" />
                <view class="content-item-box">
                    <view class="content-item-title">{{item.title}}</view>
                    <view class="content-item-name">
                        <view class="flex-row">
                            <view style="color:#808080">{{item.info}}</view>
                            <view style="height:10rpx"></view>
                        </view>
                    </view>
                </view>
            </view>
        </block>
    </view>
    <view class="content-right">
        <block wx:for="{{list}}" wx:key="list" wx:if="{{index % 2 == 1}}">
            <view class="content-item" bindtap="detail" data-v="{{item}}">
                <image src="{{item.image}}" class="content-item-img" mode="widthFix" />
                <view class="content-item-box">
                    <view class="content-item-title">{{item.title}}</view>
                    <view class="content-item-name">
                        <view class="flex-row">
                            <view style="color:#808080">{{item.info}}</view>
                            <view style="height:10rpx"></view>
                        </view>
                    </view>
                </view>
            </view>
        </block>
    </view>
</view>

item.xxx这些东西根据自己的需求进行定义

wxss:

css 复制代码
.content {
    display: flex;
    justify-content: space-around;
}
.content-left,
.content-right {
    width: 49%;
}
.content-item {
    margin: 10rpx auto 20rpx;
    background: #fff;
    width: 98%;
    border-radius: 20rpx;
    overflow: hidden;
}
.content-item-img {
    width: 100%;
}
.content-item-box {
    width: 95%;
    margin-left: 2.5%;
    font-size: 24rpx;
    color: #333;
    padding: 5rpx;
    box-sizing: border-box;
}
.content-item-title {
    /* 一行省略 */
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
    font-size: 16px;
    font-weight: 500;
}
 
.content-item-name {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20rpx;
    font-size: 22rpx;
}

js:

javascript 复制代码
//index.js
Component({
    properties: {
        list: {
            type: Array,
            defaultValue: []
        }
    },
    methods: {
       
        //wxml中绑定的事件在此处定义
    }
  });

使用瀑布流的页面,在其json文件中先引人
2.

javascript 复制代码
{
  "navigationBarTitleText": "",
  "usingComponents": {
    "waterfull": "/component/Waterfull/Waterfull",
  }
}

wxml页面使用组件

html 复制代码
<waterfull list="{{list}}"></waterfull>

{{list}}为要传过去的数组对象也就是需要生成瀑布流的数据

相关推荐
说私域2 小时前
基于定制开发开源AI智能名片S2B2C商城小程序的首屏组件优化策略研究
人工智能·小程序·开源·零售
Uyker13 小时前
微信小程序动态效果实战指南:从悬浮云朵到丝滑列表加载
前端·微信小程序·小程序
happyCoder17 小时前
uniapp 微信小程序实现定时消息订阅提醒(前后端)
微信小程序
Uyker1 天前
从零开始制作小程序简单概述
前端·微信小程序·小程序
打小就很皮...1 天前
HBuilder 发行Android(apk包)全流程指南
前端·javascript·微信小程序
说私域2 天前
定制开发开源AI智能名片驱动下的海报工厂S2B2C商城小程序运营策略——基于社群口碑传播与子市场细分的实证研究
人工智能·小程序·开源·零售
说私域2 天前
内容力重塑品牌增长:开源AI大模型驱动下的智能名片与S2B2C商城赋能抖音生态种草范式
人工智能·小程序·开源·零售
前端缘梦2 天前
微信小程序登录方案实践-从账号体系到用户信息存储
前端·微信小程序
coding随想2 天前
2025年小程序开发全解析:技术储备、行业趋势与实战案例
微信小程序
Nueuis2 天前
微信小程序前端面经
前端·微信小程序·小程序