From 336d8a39d2768cf44e772bf460934702dc1240c7 Mon Sep 17 00:00:00 2001 From: bob <312777916@qq.com> Date: Sat, 29 Mar 2025 22:54:46 +0800 Subject: [PATCH] =?UTF-8?q?ReachBottom=E6=97=B6=E7=AD=89list=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/message/MessageLayout.vue | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/views/message/MessageLayout.vue b/src/views/message/MessageLayout.vue index d9f52e4..ad354ef 100644 --- a/src/views/message/MessageLayout.vue +++ b/src/views/message/MessageLayout.vue @@ -603,14 +603,25 @@ const updateScroll = () => { * @param behavior smooth 平滑的, instant 立即(默认) */ const msgListReachBottom = (behavior = 'instant') => { - setTimeout(() => { - msgListDiv.value?.scrollTo({ + const scrollToBottom = () => { + msgListDiv.value.scrollTo({ top: msgListDiv.value.scrollHeight, behavior: behavior }) newMsgTips.value.isShowBottomTips = false disToBottom.value = 0 - }, 0) + } + + if (msgListDiv.value) { + scrollToBottom() + } else { + const stopWatch = watch(msgListDiv, (newValue) => { + if (newValue) { + scrollToBottom() + stopWatch() // 停止监听 + } + }) + } } const onReturnBottom = () => {