当前位置: 首页 > news >正文

解决微信小程序recycle-view使用百分比单位控制宽高时出现的内容溢出问题

recycle-view是微信小程序官方推出的一个经过优化的长列表组件,但是在使用百分比单位控制高宽时有个内容溢出问题,虽然它提供了height和width的参数可以设置宽高,但每次写列表都需要去js里获取宽高并设置是较为麻烦的,所以现在来着手解决使用百分比单位设置宽度时碰到的内容溢出问题。

先看看问题怎么复现:

1.先添加组件依赖:

{"usingComponents": {"recycle-view": "miniprogram-recycle-view/recycle-view","recycle-item": "miniprogram-recycle-view/recycle-item"}
}

2.编写wxml:

<view id="root" style="height: 100%;"><view style="height:50%;width: 100%;background-color: blue;"><recycle-view batch="{{batchSetRecycleData}}" id="recycleId"><recycle-item wx:for="{{1000}}" wx:key="id"><view style="width: 100px;height: 100px;">1234</view></recycle-item></recycle-view></view>
</view>

wxss:

page {width: 100%;height: 100%;
}

3.查看界面

4.现在来说一下问题,首先是界面显示了一个基于recycleview的列表,然后他的父元素我给他设置了height:50%,按理来说这个列表的区域也应该是Page内容区域高度的50%,也就是和蓝色区域重合,但是他现在内容溢出了

这明显是不合理的,接下来是修复

1.打开miniprogram_npm/miniprogram-recycle-view/recycle-view.wxml,编辑最外层的view的style,直接改为height:100%;width:100%

<!--components/recycle-view/recycle-view.wxml-->
<view bindtouchstart='_beginToScroll' style="height:100%;width:100%;" id="content" class="wrap"><scroll-view bindscroll="_scrollViewDidScroll" class="content" style='height:100%;position: relative;' scroll-y="{{useInPage ? false : scrollY}}" scroll-x="{{false}}" upper-threshold="{{upperThreshold}}" lower-threshold="{{lowerThreshold}}" scroll-top="{{innerScrollTop}}" scroll-into-view="{{innerScrollIntoView}}" scroll-with-animation="{{scrollWithAnimation}}" bindscrolltoupper="_scrollToUpper" bindscrolltolower="_scrollToLower" scroll-anchoring enable-back-to-top="{{enableBackToTop}}" throttle="{{throttle}}"><view style="position: absolute;z-index:1;width:100%;left: 0;top: 0;opacity: 0;visibility: hidden;"><slot name="itemsize"></slot></view><view style="height:{{hasBeforeSlotHeight ? beforeSlotHeight + 'px' : 'auto'}}" class="slot-before"><slot name="before"></slot></view><view style='position:relative;width:100%;z-index:10;background: url("{{placeholderImageStr}}") repeat;height:{{totalHeight}}px;'><!-- <view class='before' style="height:{{innerBeforeHeight}}px"></view> --><view style="position: absolute;left:0;width:100%;top:{{innerBeforeHeight}}px;"><slot></slot></view><!-- <view class='after' style="height:{{innerAfterHeight}}px"></view> --></view><view style="height:{{hasAfterSlotHeight ? afterSlotHeight + 'px' : 'auto'}}" class="slot-after"><slot name="after"></slot></view></scroll-view>
</view>

2.打开miniprogram_npm/miniprogram-recycle-view/recycle-view.wxss,将:host{}删除或者注释

/* components/recycle-view/recycle-view.wxss */
/* :host {display: block;width: 100%;
} */

3.运行看看效果:

内容不溢出了,而且滚动效果也正常。

微信小程序代码片段(需要手动安装recycleview依赖):https://developers.weixin.qq.com/s/J3TFLYmQ71K1

http://www.lryc.cn/news/154120.html

相关文章:

  • 如何使用蚂蚁集团自动化混沌工程 ChaosMeta 做 OceanBase 攻防演练?
  • 在 Node.js 中使用 MongoDB 事务
  • IntelliJ IDEA的远程开发(Remote Development)
  • 网络安全-信息收集简介
  • 页面页脚部分CSS分享
  • 微信小程序slot插槽的介绍,以及如何通过uniapp使用动态插槽
  • l8-d6 socket套接字及TCP的实现框架
  • ChatGPT AIGC 完成动态堆积面积图实例
  • 虹科产线实时数采检测方案——高速采集助力智能化升级
  • 用迅为RK3568开发板使用OpenCV处理图像颜色通道提取ROI
  • 低压配电室电力安全解决方案
  • 【Windows 常用工具系列 11 -- 笔记本F5亮度调节关闭】
  • Python小知识 - 【Python】如何使用Pytorch构建机器学习模型
  • 使用Akka的Actor模拟Spark的Master和Worker工作机制
  • 文心一言api接入如何在你的项目里使用文心一言
  • Python匿名函数lambda(R与Python第五篇)
  • 【2023校园招聘】 钉钉AI应用开发平台开始校招拉~
  • Linux系统gdb调试常用命令
  • Sumo中Traci.trafficlight详解(上)
  • 手写Mybatis:第13章-通过注解配置执行SQL语句
  • spring security - 快速整合 springboot
  • NPM 常用命令(二)
  • ctfhub ssrf(3关)
  • 跨源资源共享(CORS)Access-Control-Allow-Origin
  • 【嵌入式软件开发 】学习笔记
  • CentOS 7上安装Python 3.11.5,支持Django
  • COMPFEST 15H「组合数学+容斥」
  • react快速开始(三)-create-react-app脚手架项目启动;使用VScode调试react
  • 【C++入门】string类常用方法(万字详解)
  • 大数据错误