欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > 微信小程序瀑布流组件

微信小程序瀑布流组件

2025/2/25 9:41:19 来源:https://blog.csdn.net/weixin_45381071/article/details/143786474  浏览:    关键词:微信小程序瀑布流组件

实现思路

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

示例

  • backTop() 返回顶部
  • Init(arr) 接收下一个显示的数组
<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>

源代码

微信小程序瀑布流组件

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词