参考:参考
/**
* @author gongliying
* @date 2019-07-26
* @information 跳转页面底部
*/
scrollToBottom: function () {
let that = this;
let query = uni.createSelectorQuery();
query.selectAll('.m-item').boundingClientRect();
query.select('#scrollview').boundingClientRect();
query.exec((res) => {
that.style.mitemHeight = 0;
res[0].forEach((rect) => that.style.mitemHeight = that.style.mitemHeight + rect.height + 40) //获取所有内部子元素的高度
// 因为vue的虚拟DOM 每次生成的新消息都是之前的,所以采用异步setTimeout 主要就是添加了这红字 setTimeout(() => {
if (that.style.mitemHeight > (that.style.contentViewHeight - 100)) { //判断子元素高度是否大于显示高度
that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight //用子元素的高度减去显示的高度就获益获得序言滚动的高度
} }, 100)
})
}
export default {
created () { const res = uni.getSystemInfoSync(); //获取手机可使用窗口高度 api为获取系统信息同步接口 this.style.pageHeight = res.windowHeight; this.style.contentViewHeight = res.windowHeight - uni.getSystemInfoSync().screenWidth / 750 * (100) - 70; //像素 因为给出的是像素高度 然后我们用的是upx 所以换算一下 this.scrollToBottom(); //创建后调用回到底部方法 },
data (){
// 聊天页面时时滚动样式
return
style: {
pageHeight: 0,
contentViewHeight: 0,
footViewHeight: 90,
mitemHeight: 0
}, }}
但是不知道,如何在进入页面之后,马上滑动到最底部。原文一句话:“要是想要进入页面就滚到最底部呢 我们是在socket链接读取文件的时候调用了这个方法”,看不懂,不知道在哪里调用