微信小程序瀑布流组件

实现思路

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

源代码

微信小程序瀑布流组件

相关推荐
LeoZY_14 小时前
开源项目精选:Dear ImGui —— 轻量高效的 C++ 即时模式 GUI 框架
开发语言·c++·ui·开源·开源软件
换日线°15 小时前
NFC标签打开微信小程序
前端·微信小程序
进击monkey21 小时前
PandaWiki:开源私有化AI知识库,解救企业知识管理困境
开源软件·ai知识库·ai wiki
菜鸟una1 天前
【微信小程序+Taro 3+NutUI 3】input (nut-input) 、 textarea (nut-texteare)类型使用避坑
前端·vue.js·微信小程序·小程序·taro
计算机毕设指导61 天前
基于微信小程序的校园二手交易系统【源码文末联系】
java·spring boot·spring·微信小程序·小程序·tomcat·maven
Java.慈祥2 天前
速通-微信小程序 2Day
微信小程序·小程序·前端框架
千桐科技2 天前
qData 数据中台开源版 1.1.2 版本更新公告:新增 Apache Doris 数据源全面支持,稽查规则与转换组件持续完善
开源软件·数据治理·doris·数据集成·大数据平台·数据中台·qdata
2501_933907212 天前
宁波小程序公司是什么?主要提供宁波微信小程序制作与服务吗?
科技·微信小程序·小程序
黄美美分享2 天前
【免费开源】多平台直播录制软件!支持 40 + 平台直播录制,附软件下载!
windows·自动化·电脑·开源软件
码云数智-大飞2 天前
微信商城小程序怎么弄?2026年主流小程序商城平台对比
微信小程序