微信小程序瀑布流组件

实现思路

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

源代码

微信小程序瀑布流组件

相关推荐
梦梦代码精11 小时前
LikeShop按摩到家系统:2026年本地生活创业新风口,上门服务O2O源码私有化部署实战
大数据·docker·小程序·uni-app·生活·高并发·开源软件
郝学胜-神的一滴12 小时前
Qt 高级开发 008: 使用QSetting记住上次打开路径
开发语言·c++·qt·开源软件
这是个栗子13 小时前
【uni-app微信小程序问题解决】Uni-app 微信小程序组件不渲染
微信小程序·小程序·uni-app
倒流时光三十年13 小时前
第四章 WXSS 样式系统与布局
spring boot·微信小程序
Hotakus14 小时前
[开源] 关于我给OpenCode弄了个缓存统计插件这件事 OpenCode Visual Cache
缓存·typescript·开源软件
爱学习 爱分享1 天前
微信小程序html 在 webview 会打开再缩放一下
微信小程序·小程序·html
梦梦代码精1 天前
深度拆解:上门按摩系统如何成为本地生活“到家时代”的新引擎?
docker·小程序·uni-app·开源·生活·开源软件
xshirleyl2 天前
微信小程序开发week6-慕尚花坊项目
微信小程序·小程序
好赞科技2 天前
2026年八大上门服务预约小程序:解锁高效生活新体验
大数据·微信小程序
郝学胜-神的一滴2 天前
Qt 高级开发 007: 图片查看器案例
开发语言·c++·qt·程序人生·开源软件