微信小程序瀑布流组件

话不多说直接上干货:

现在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 小时前
拯救你的app/小程序审核!一套完美避开审核封禁的URL黑名单机制
前端·javascript·微信小程序
weixin_lynhgworld11 小时前
盲盒抽谷机小程序系统开发:从0到1的完整方法论
小程序
weixin_lynhgworld11 小时前
短剧小程序系统开发:赋能创作者,推动短剧艺术创新发展
小程序
江湖有缘13 小时前
【Docker项目实战】使用Docker部署Notepad轻量级记事本
docker·容器·notepad++
一匹电信狗14 小时前
【C++】异常详解(万字解读)
服务器·c++·算法·leetcode·小程序·stl·visual studio
我叫黑大帅15 小时前
微信小程序分包:告别加载慢,像拆快递一样简单!
前端·微信小程序
腾讯云qcloud075518 小时前
腾讯位置商业授权微信小程序关键词输入提示
notepad++
两个月菜鸟18 小时前
vue+微信小程序 五角星
前端·vue.js·微信小程序
说私域1 天前
基于开源AI智能客服、AI智能名片与S2B2C商城小程序的微商服务优化及复购转介绍提升策略研究
人工智能·小程序