经过实际验证,我使用 wx.pageScrollTo() 在 onReady() 中滚动页面,这个效果只在 tab 页面上可用,在子页面使用会让用户迷惑。
onReady() { const height = this.data.projectNum * 90 + 92 // 计算出页面高度 wx.pageScrollTo({ scrollTop: height, duration: 300 }) },下面是网上找的代码,实测效果不好:
// 获取容器高度,使页面滚动到容器底部 pageScrollToBottom: function() { wx.createSelectorQuery().select('#j_page').boundingClientRect(function(rect){ // 使页面滚动到底部 wx.pageScrollTo({ scrollTop: rect.bottom + 5000 }) }).exec() },- j_page为页面容器的id
- 使用 rect.bottom, rect.height 均能达到滚动到底部的效果
- 在数据更新后(setData回调函数)使用
按理说,滚动到 rect.bottom,就可以了。但实际中发现滚不到底,索性加上 5000。
https://segmentfault.com/q/1010000012493589/a-1020000012494791














