微信小程序瀑布流组件

实现思路

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

源代码

微信小程序瀑布流组件

相关推荐
狼性书生16 小时前
uniapp+vue3实现的简单吐司通知弹窗组件
前端·uni-app·vue·组件·插件
计算机毕设指导619 小时前
基于微信小程序的社区医疗服务管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
fengGer的bugs20 小时前
微信小程序版「死了么APP」,它来了
微信小程序·小程序·死了么·死了么app
我的86呢!20 小时前
微信小程序蓝牙配网
微信小程序·小程序
花卷HJ20 小时前
【微信小程序】open-type=“contact“ 客服按钮样式无法设置?隐藏 button + label 触发完美解决
微信小程序·小程序·notepad++
qq_124987075321 小时前
基于springboot的文化旅游小程序(源码+论文+部署+安装)
java·spring boot·后端·微信小程序·小程序·毕业设计·旅游
计算机毕设指导62 天前
基于微信小程序民宿预订管理系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
P7Dreamer2 天前
微信小程序处理Range分片视频播放问题:前端调试全记录
前端·微信小程序
苦夏木禾2 天前
在微信小程序中,同样的宽度100%,textarea和其他标签的实际宽度不一样
微信小程序·小程序
岁岁种桃花儿2 天前
Spring Boot核心插件全解析(官方+第三方,附使用场景)
log4j·springboot·插件