微信小程序瀑布流组件

话不多说直接上干货:

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

相关推荐
低代码布道师7 小时前
教培管家第11讲:班级管理——教务系统的“集成枢纽”
低代码·小程序·云开发
数字游民95277 小时前
小程序上新,猜对了么更新110组素材
人工智能·ai·小程序·ai绘画·自媒体·数字游民9527
小小王app小程序开发10 小时前
盲盒随机赏小程序核心玩法拆解与运营逻辑分析
大数据·小程序
说私域10 小时前
AI智能名片链动2+1模式小程序在消费者商家全链路互动中的应用研究
大数据·人工智能·小程序·流量运营·私域运营
不爱学习小趴菜11 小时前
uniapp微信小程序无法屏蔽右上角胶囊按钮(...)问题解决方案
微信小程序·小程序·uni-app
StarChainTech11 小时前
打造火爆的线上推币机APP:一站式合规娱乐解决方案
大数据·人工智能·物联网·小程序·娱乐·软件需求·共享经济
plmm烟酒僧11 小时前
《微信小程序demo开发》第一部分-编写页面逻辑
javascript·微信小程序·小程序·html·微信开发者工具·小程序开发
2501_9160088911 小时前
iOS 开发助手工具,设备信息查看、运行日志、文件管理等方面
android·ios·小程序·https·uni-app·iphone·webview
Stara051112 小时前
微信小程序配置与导航深度指南—全局/页面配置解析与高效传参策略V1.2
javascript·微信小程序·html·模块化开发·页面导航·wxs脚本·小程序api
EstherNi12 小时前
小程序中,下拉多选的组件,有写死的三级下拉,样式需要修改
javascript·小程序·vue