微信小程序 DOM 问题

news/2024/7/7 20:48:09 标签: 微信小程序

DOM 渲染问题

问题

Dom limit exceeded, please check if there's any mistake you've made.

测试页面 1

<template>
	<scroll-view @scroll="screen" style="width: 100%;height: 100vh;" :scroll-y="true" :scroll-with-animation="true"
		@scrolltolower="scrolltolower">
		<view v-for="(v,i) in list" :key="i" :id="'page'+i" :style="{height:v.height ? v.height+'px':'auto'}">
			<block v-if="v&&v.length>0" >
			<view style="width: 100%;height: 160rpx;background-color: aqua;color: red;margin-top: 20rpx;" v-for="d in v"
				:key="d">{{d}}</view>
			</block>
		</view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				list2: [],
				page: 1
			}
		},
		onLoad() {
			this.loadData()
		},
		methods: {
			screen(e){
				    this.index = this.index ? this.index : 0;
				    this.windowHeight = this.windowHeight ? this.windowHeight : wx.getSystemInfoSync().windowHeight;
				    this.boundings.forEach((item, index) => {
				      if ((item.top < e.detail.scrollTop + this.windowHeight) && (e.detail.scrollTop + this.windowHeight <= item.bottom)) {
				        this.index = index;
				      }
				    })
				    this.list.forEach((item, index) => {
				      if ((index == this.index || index == this.index - 1 || index == this.index - 2 || index == this.index + 1 || index == this.index + 2) &&
				        this.list[index] && !Array.isArray(this.list[index])
				      ) {
				        this.list[index] = this.list2[index]
				      }
				      if ((index > this.index + 2 || index < this.index - 2) && Array.isArray(this.list[index])) { 
						this.list[index] = { height: this.boundings[index].height }
				      }
				    }) 
			},
			scrolltolower() { 
				this.page += 1
				wx.showLoading()
				setTimeout(() => {
					this.loadData()
				}, 500)
			},
			loadData() {
				let data1 = [];
				for (let i = 0; i < 10; i++) {
					data1.push(1 + i + (this.page - 1) * 10)
				}
				if (this.page == 1) {
					this.list = [];
					this.list2 = [];
				}

				this.list[this.page - 1] = data1;
				this.list2[this.page - 1] = data1;

				
				this.$nextTick(() => { 
					setTimeout(()=>{
						this.boundings = Array.isArray(this.boundings) ? this.boundings : [];
						let index = this.page - 1;
						// wx.createSelectorQuery().select(`#page${index}`).boundingClientRect((rect) => {
						//	this.boundings[index] = {
						//		height: rect.height,
						//			top: index == 0 ? rect.top : this.boundings[index - 1].top + this
						//			.boundings[index - 1]
						//			.height,
						//			bottom: index == 0 ? rect.bottom : this.boundings[index - 1].bottom + rect
						//			.height
						//	};
						//	}).exec()

						const query = uni.createSelectorQuery().in(this);
					 	 query.select(`#page${index}`).boundingClientRect(rect => {
					    	// console.log(rect);
							this.boundings[index] = {
								height: rect.height,
								top: index == 0 ? rect.top : this.boundings[index - 1].top + this
									.boundings[index - 1]
									.height,
								bottom: index == 0 ? rect.bottom : this.boundings[index - 1].bottom + rect
									.height
							};
					  }).exec();
					},300)
				})
				wx.hideLoading()
			},
		},
	}
</script>

<style>
	.list-item {
		height: 200rpx;
		background: #ddd;
		display: flex;
		align-items: center;
		justify-content: center;
		border-bottom: 1px solid #fff;
	}
</style>

滑动过快触发多次到底事件

			loadData() {
				this.isPdFalse2 = this.isPdFalse2 ? this.isPdFalse2 : false;
				if(this.isPdFalse2) return true;
				this.isPdFalse2 = true;
					
				let data1 = [];
				for (let i = 0; i < 10; i++) {
					data1.push(1 + i + (this.page - 1) * 10)
				}
				if (this.page == 1) {
					this.list = [];
					this.list2 = [];
				}

				this.list[this.page - 1] = data1;
				this.list2[this.page - 1] = data1;

				
				this.$nextTick(() => { 
					setTimeout(()=>{
						this.boundings = Array.isArray(this.boundings) ? this.boundings : [];
						let index = this.page - 1;
						wx.createSelectorQuery().select(`#page${index}`).boundingClientRect((rect) => {
							this.boundings[index] = {
								height: rect.height,
								top: index == 0 ? rect.top : this.boundings[index - 1].top + this
									.boundings[index - 1]
									.height,
								bottom: index == 0 ? rect.bottom : this.boundings[index - 1].bottom + rect
									.height
							};
						}).exec()
						this.isPdFalse2 = false;
					},300)
				})

				// 数据获取不成功时
				// this.isPdFalse2 = false;
				wx.hideLoading()
			}

测试页面 2

<template>
	<scroll-view @scroll="screen" style="width: 100%;height: 100vh;" :scroll-y="true" :scroll-with-animation="true"
		@scrolltolower="scrolltolower">
		<view v-for="(v,i) in list" :key="i" :id="'listpage-'+i">
			<block v-if="i - currentPage >= -1 && i - currentPage <= 1">
				<view style="width: 100%;height: 160rpx;background-color: aqua;color: red;margin-top: 20rpx;"
					v-for="d in v" :key="d">{{d.name}}</view>
			</block>
		</view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				currentPage: 0,
				pageSize: 10,
				list: [],
				pageFrame: [],
				inPageUpdate: false
			}
		},
		onLoad: function() {
			this.scrolltolower()
		},
		methods: {
			screen(e) {
				if (this.inPageUpdate) {
					return;
				}
				var {
					scrollTop
				} = e.detail;
				// console.log(this.currentPage)
				if (this.currentPage > 0) {
					var pageFrame = this.pageFrame[this.currentPage - 1];
					// console.log(pageFrame,1)
					var screenHeight = wx.getSystemInfoSync().screenHeight;
					// console.log(screenHeight,1)
					if ((scrollTop + screenHeight) - (pageFrame.lastBottom + pageFrame.height) < -200) {
						this.inPageUpdate = true;
						this.currentPage -= 1;
						this.inPageUpdate = false;
					}
				}
				var currentPageFrame = this.pageFrame[this.currentPage];
				// console.log(currentPageFrame,2)
				if (currentPageFrame) {
					if (scrollTop - (currentPageFrame.lastBottom + currentPageFrame.height) > 200) {
						this.inPageUpdate = true;
						this.currentPage += 1;
						this.inPageUpdate = false;
					}
				}
			},
			scrolltolower() {
				if (this.inPageUpdate) {
					return;
				}

				var list = [];
				for (var i = 0; i < 100; i++) {
					list.push({
						name: '999999999----' + i
					});
				}
				this.list = [...this.list, list]



				this.inPageUpdate = true;
				if (this.currentPage < this.list.length - 1) {
					var self = this;
					var currentPage = this.currentPage;
					self.$nextTick(() => {

						const query1 = uni.createSelectorQuery().in(this);
						query1.select('#listpage-' + this.currentPage).boundingClientRect(
							function(rect) {
								console.log(rect, 1)
								if (currentPage > 0) {
									rect.lastBottom = self.pageFrame[currentPage - 1].height + self.pageFrame[
										currentPage - 1].lastBottom
								} else {
									rect.lastBottom = 0;
								}
								self.pageFrame[`${currentPage}`] = rect
							}).exec();
						this.currentPage = this.currentPage + 1;
						var nextPage = this.list[this.currentPage];
						var key = `${this.currentPage}`

						this.list[key] = nextPage;

						this.inPageUpdate = false;
					})

				} else {
					this.inPageUpdate = false;
				}

			}
		}
	}
</script>

<style>

</style>

http://www.niftyadmin.cn/n/5535326.html

相关文章

vue使用scrollreveal和animejs实现页面滑动到指定位置后再开始执行动画效果

效果图 效果链接&#xff1a;http://website.livequeen.top 介绍 一、Scrollreveal ScrollReveal 是一个 JavaScript 库&#xff0c;用于在元素进入/离开视口时轻松实现动画效果。 ScrollReveal 官网链接&#xff1a;ScrollReveal 二、animejs animejs是一个好用的动画库…

大数据------JavaWeb------MyBatis(完整知识点汇总)

MyBatis MyBatis简介 定义 它是一款优秀的持久层框架&#xff0c;用于简化JDBC开发它原来是Apache的一个开源项目iBatis&#xff0c;后来改名为MyBatis中文官网&#xff1a;https://mybatis.org/mybatis-3/zh_CN/index.html JaveEE三层架构 表现层&#xff08;做页面展示&…

什么是代理IP?代理IP有什么好处呢?

在互联网的世界里&#xff0c;每台设备都有一个独特的身份标识&#xff0c;即IP地址。这个IP地址不仅仅是一串数字&#xff0c;它代表着设备在网络中的位置&#xff0c;同时也可能暴露用户的地理位置和其他个人信息。为了保护用户的隐私&#xff0c;提高网络安全&#xff0c;或…

基于Transformer的端到端的目标检测 | 读论文

本文正在参加 人工智能创作者扶持计划 提及到计算机视觉的目标检测&#xff0c;我们一般会最先想到卷积神经网络&#xff08;CNN&#xff09;&#xff0c;因为这算是目标检测领域的开山之作了&#xff0c;在很长的一段时间里人们都折服于卷积神经网络在图像处理领域的优势&…

7-494 结构体数组实现工资数据的存放与输出(结构体)

用结构体存放下表中的数据&#xff0c;然后输出每人的姓名和实发工资&#xff08;基本工资浮动工资-支出&#xff09; 输入格式: 在每一行输入姓名&#xff0c;基本工资&#xff0c;浮动工资及支出 输出格式: 每一行输出姓名及实发工资 输入样例: 在这里给出一组输入。例…

C语言力扣刷题11——打家劫舍1——[线性动态规划]

力扣刷题11——打家劫舍1和2——[线性动态规划] 一、博客声明二、题目描述三、解题思路1、线性动态规划 a、什么是动态规划 2、思路说明 四、解题代码&#xff08;附注释&#xff09; 一、博客声明 找工作逃不过刷题&#xff0c;为了更好的督促自己学习以及理解力扣大佬们的解…

MySQL高级-SQL优化-insert优化-批量插入-手动提交事务-主键顺序插入

文章目录 1、批量插入1.1、大批量插入数据1.2、启动Linux中的mysql服务1.3、客户端连接到mysql数据库&#xff0c;加上参数 --local-infile1.4、查询当前会话中 local_infile 系统变量的值。1.5、开启从本地文件加载数据到服务器的功能1.6、创建表 tb_user 结构1.7、上传文件到…

一篇文章说清楚Filter(过滤器)、Interceptor(拦截器)和AOP(切面儿)

文章目录 前言一、Filter&#xff08;过滤器&#xff09;1.说明2.实现filterChain.doFilter() 3.order优先级4.解决跨域5.拦截返回错误信息JSON 二、Interceptor&#xff08;拦截器&#xff09;1.说明2.实现preHandlepostHandleafterCompletion 3.执行顺序图4.排除特定路径拦截…