通用网址查询网站,银川网站建设推广,苏中建设官方网站,南京seo排名公司文章目录 bug描述原因分析: 处理方案 bug描述
1.点击的A页面, 跳转到了B页面, 第一次页面正常显示 2.从B页面返回A页面 3.A页面不进行任何操作,再次点击A页面进入B页面 4.B页面自动滚动到底部.
原因
看一段A页面代码 let that thisthis.defaultScrollTop uni.getStorageSy… 文章目录 bug描述原因分析: 处理方案 bug描述
1.点击的A页面, 跳转到了B页面, 第一次页面正常显示 2.从B页面返回A页面 3.A页面不进行任何操作,再次点击A页面进入B页面 4.B页面自动滚动到底部.
原因
看一段A页面代码 let that thisthis.defaultScrollTop uni.getStorageSync(detailScrollTop)this.$nextTick(() {that.getInfoHeight();that.getPostion()clearTimeout(this.timer)this.timer setTimeout(() {if (that.courseInfo.unlock ! 0 that.courseInfo.catalog that.courseInfo.catalog.length) {if (this.firstLoad) {that.switchClick(2)} else {if (!this.firstLoad) {console.log(jump to page)console.log(this.defaultScrollTop, ----)uni.pageScrollTo({scrollTop: this.defaultScrollTop,duration: 150})}}this.firstLoad false}}, 300)})分析:
此处代码仅在 onLoad中调用, 按理说和点击事件毫无关系
最后排查发现 问题出在事件循环上
this.$nextTick((){}) 所以在路由跳转后, A页面的该回调函数被调用,此时的回调触发uni.pageScrollTo 就造成了在B页面诡异的滚动到底部问题
处理方案
移除 jsthis.$nextTick((){}) 或者在A页面做逻辑判断