使用场景:实现同微信飞书发送消息框内展示最新发送的与最新收到的。
解决方法
使用异步处理setTimeout函数获取最新的scrollHeight
// 页面滚动
scrollToBottom () {
this.$nextTick(() => {
const container = document.getElementById('scroll')
container.scrollTop = container.scrollHeight
})
},
发送完或者收到最新消息之后调用scrollToBottom()方法即可。