参考:uniapp 消息列表进入详情后页面返回时保存当前位置
onPageScroll()记录当前的高度位置
onPageScroll(e) {this.scrollTop = e.scrollTopconsole.log("this.scrollTop", this.scrollTop);},
跳转页面的逻辑里缓存上次的高度值
// 查看逻辑tjshow(val, scrollTop) {this.lastScrollTop = scrollTop;console.log("this.lastScrollTop: ", this.lastScrollTop);}
返回之前页面时,使用缓存值定位页面位置
这里要使用setTimeout()
// 返回前页面actionFormClose() {// 重置actionFormthis.actionForm = this.$options.data().actionFormlet timer = setTimeout(() => {uni.pageScrollTo({scrollTop: this.lastScrollTop, //距离页面顶部的距离duration: 0});}, 0)},
