微信小程序瀑布流组件

实现思路

  • 布局采用左右风格的方式,图片采用宽度固定自适应高度
  • 接收到显示的数组循环获取左右的高度对比下一个插入左或右
  • 提供左右插槽可自定义布局,传出当前循环的值与下标
  • 提供触底事件与返回顶部事件
  • 在滚动过程中隐藏不需要显示的数据以减少微信小程序dom的消耗

示例

  • backTop() 返回顶部
  • Init(arr) 接收下一个显示的数组
javascript 复制代码
<template>
    <view style="display: flex;flex-direction: column;width: 100%;height: 100wh;">
        <view class="ddddd">
            <ZzzVue @scrolltolower="jhjj2" ref="leftright">
                <template v-slot:left="{data,dataIndex}">
                    <image :src="data"
                        style="width: 100%;display: block;margin: 0;padding: 10rpx;box-sizing: border-box;"
                        mode="widthFix"></image>
                </template>
                <template v-slot:right="{data,dataIndex}">
                    <image :src="data"
                        style="width: 100%;display: block;margin: 0;padding: 10rpx;box-sizing: border-box;"
                        mode="widthFix"></image>
                </template>
            </ZzzVue>
        </view>
        <view @click="jhjj2()" style=" line-height: 90rpx;background: #ccc;">下一页</view>
        <view @click="jhjj333()" style=" line-height: 90rpx;background: #ccc;">返回顶部</view>
    </view>
</template>

<script>
    import a1 from '../../static/1.jpg'
    import a2 from '../../static/2.jpg'
    import ZzzVue from '../Component/Compent.vue'
    export default {
        components: {
            ZzzVue
        },
        data() {
            return {
                arrList: [a1,
                    a2
                ],
                tempList: []
            }
        },
        onLoad() {
            var d = [...this.arrList];
            for (let i = 0; i < 5; i++) {
                this.arrList = [...this.arrList, ...d]
            }
            this.tempList = [...this.arrList]

            this.$nextTick(() => {

                this.$refs.leftright.Init(this.arrList)
            })
        },
        methods: {
            jhjj333() {

                this.$nextTick(() => {

                    this.$refs.leftright.backTop()
                })
            },
            jhjj2() {
                this.$nextTick(() => {

                    this.$refs.leftright.Init(this.tempList)
                })
            },
        }
    }
</script>

<style>
    .ddddd {
        width: 100%;
        height: 80vh;
    }
</style>

源代码

微信小程序瀑布流组件

相关推荐
沉默-_-12 小时前
微信小程序网络请求 wx.request 详解
网络·学习·微信小程序·小程序
沉默-_-13 小时前
微信小程序页面配置详解
学习·微信小程序·apache·微信开发者工具
帆张芳显18 小时前
智表zcell产品V3.5 版发布,新增行列选中操作等功能
前端·javascript·excel·插件·canva可画
逆龙泰氽19 小时前
微信小程序开发04-1(小程序API)
微信小程序·小程序
千桐科技20 小时前
qData 数据中台开源版 v1.1.1 发布:动态游标同步技术上线,SQL Server 2008 全面支持
开源软件·sql server·工程化·数据同步·数据中台·qdata·动态游标
苏苏哇哈哈20 小时前
微信小程序实现高性能动态配置水滴凹槽、凸起Tabbar 组件
微信小程序·小程序
逆龙泰氽21 小时前
微信小程序开发03(WXML语法)
微信小程序·小程序
jackletter1 天前
3dsmax2026插件开发入门:使用.net8开发
.net·3dmax·入门·插件·.net8·3dsmax2026
UpYoung!2 天前
【VMware 17】虚拟化软件——VMware 17 Pro 详细图文完全教程:桌面虚拟化的行业标杆
开源软件·vmware·虚拟化·虚拟化工具·运维必备·虚拟化平台·vmvare 17
毕设源码-邱学长2 天前
【开题答辩全过程】以 基于微信小程序的课程表信息系统的开发实现为例,包含答辩的问题和答案
微信小程序·小程序