微信小程序瀑布流组件

话不多说直接上干货:

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

wxml:

javascript 复制代码
    <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文件中先引人

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

wxml页面使用组件

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

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

相关推荐
weishuangyun1232 小时前
微信小程序怎么选公司?上线流程详解
大数据·小程序
show43311 小时前
2026微信小程序视频转文字多语种识别引擎技术选型:22种方言25种外语挑战
微信小程序·小程序·音视频
lhldsg17 小时前
县城外卖系统开发实战:从需求分析到上线全流程指南
java·小程序·需求分析
Kingexpand_com20 小时前
旅游小程序怎么选型?模板与定制二次开发技术对比解析
小程序·旅游·小程序开发·旅行·定制开发
万岳科技系统开发20 小时前
外卖跑腿小程序如何提升本地生活服务平台运营效率?
大数据·小程序·生活
MrFlySand_飞沙20 小时前
uniapp开发微信小程序实现接入企业微信客服
微信小程序·小程序·uni-app·企业微信
码艺-Alimjan20 小时前
JWT 的本质、误区与正确落地:一套不依赖任何框架的架构方法论-微信小程序代码案例-Api 安全性拉满
微信小程序·架构·notepad++
禁止摆烂_才浅20 小时前
微信小程序高频面试题
前端·面试·微信小程序
Ai-_Man21 小时前
豆包智能体把对话批量导出为Word或PDF的正确顺序
人工智能·ai·小程序·pdf·word
mykj155121 小时前
打车顺风车代驾小程序的核心,远不止一个页面
小程序·代驾小程序开发·顺风车小程序·出租车app