+
95
-

回答

有两种方式

一、scroll-into-view

<scroll-view scroll-y scroll-into-view='{{toView}}' style='height: 440px;overflow: auto; '>
<view id="msg-1">1</view> <view id="msg-2">2</view></scroll-view>

js中通过setdata来设置toView为最底部view的id值,比如msg-2

二、scrolltop

设置

<scroll-view scroll-y :scroll-top="scrollTop" id="scrollview" style="400px;overflow: scroll; '">
<view id="msglistview"><view>1</view> <view>2</view></view></scroll-view>

js来计算scrolltop并setdata

let that = this
let query = uni.createSelectorQuery()
query.select('#scrollview').boundingClientRect()
query.select('#msglistview').boundingClientRect()
query.exec((res) => {
// console.log(res)
if(res[1].height > res[0].height){
that.scrollTop = res[1].height - res[0].height;
console.log( that.scrollTop );
}
})



网友回复

我知道答案,我要回答