微信小程序瀑布流组件

话不多说直接上干货:

现在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}}为要传过去的数组对象也就是需要生成瀑布流的数据

相关推荐
华子w90892585916 分钟前
基于“SpringBoot+uniapp的考研书库微信小程序设计与实现7000字论文
微信小程序·小程序·uni-app
浩宇软件开发16 分钟前
基于微信小程序的校园二手交易平台
微信小程序·小程序·校园二手交易
weixin_177297220691 小时前
淘宝扭蛋机小程序系统开发:打造互动性强的购物平台
小程序
王——小喵1 小时前
启动已有小程序项目
小程序
说私域1 小时前
基于开源AI智能名片链动2 + 1模式S2B2C商城小程序的沉浸式体验营销研究
人工智能·小程序·开源·零售
柳中仙1 小时前
uniapp+vue3小程序分享
小程序·uni-app
烂笔头儿@3 小时前
uniapp开发小程序vendor.js 过大
小程序·uni-app
程序员小奕3 小时前
Springboot 高校报修与互助平台小程序
spring boot·后端·小程序
程序员阿龙5 小时前
计算机毕业设计微信小程序题库系统 在线答题 题目分类 错题本管理 学习记录查询系统源码+论文+PPT+讲解 基于微信小程序的题库系统设计与实现
微信小程序·分类·课程设计·在线答题·题库系统·错题本管理·试题分类
Li.JJ6 小时前
小程序查广州楼盘网签数据和备案价(免费)
经验分享·微信小程序