在开发聊天界面时,需求是在初次进入聊天界面和发送信息后,消息要到达最底部。代码:
pageToBottom(){
let lastIndex = this.list.length - 1
console.log(lastIndex)
if(lastIndex < 0) return;
this.scrollInto = 'chat'+lastIndex
console.log('chat'+lastIndex)
console.log(12121)
}
这个方法在onReady上可以使用,但是到了我点击发送时,发现也可以触发这个方法但是就是没有效果,还是没有回到最底部。解决办法:加一个定时器
setTimeout(()=>{
this.pageToBottom();
},100)