From df2cca374b181e4165baf806856a97819ce2b7e9 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Thu, 29 May 2025 10:13:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(im=5Fchat=5Finfo):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E6=BB=9A=E5=8A=A8=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除不必要的 scrollIntoView 和 scrollViewHeight 属性 - 添加 isFirstLoad 和 scrollTop 属性 - 修改加载完成后滚动到底部的逻辑,使用 scrollTop 属性 - 优化代码结构,提高可读性和性能 --- pages/common/im_chat_info.vue | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pages/common/im_chat_info.vue b/pages/common/im_chat_info.vue index bc709d3..ae88c48 100644 --- a/pages/common/im_chat_info.vue +++ b/pages/common/im_chat_info.vue @@ -6,6 +6,7 @@ @@ -90,7 +91,8 @@ export default { content: '',//文本内容(JSON 格式扩展字段),文本类型=纯文字,图片类型=绝对路径 }, - lastItemId: null, + isFirstLoad: true, // 标记是否为首次加载 + scrollTop:'', } }, onLoad(options) { @@ -137,16 +139,10 @@ export default { //获取聊天记录列表 await this.getList(); - // 更新最后一个 item 的 ID - this.lastItemId = 'item_' + (this.tableList.length - 1); - - // 滚动到底部 - this.$nextTick(() => { - this.$refs.scrollView.scrollTo({ top: this.scrollViewHeight }); - }); - - // 或者直接使用 scroll-into-view - this.scrollIntoView = this.lastItemId; + // 首次加载后滚动到底部 + if (this.filteredData.page == 2) { + this.scrollToBottom() + } }, //获取好友关系详情 @@ -303,6 +299,13 @@ export default { } }, + //页面滚动到底部 + scrollToBottom() { + alert(1) + this.$nextTick(() => { + this.scrollTop = 999999 // 足够大的值确保滚动到底部 + }) + }, } }