From 4f44b4f5748fa833b76f8bd30badbd4312609ecb Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Fri, 5 Jun 2026 17:39:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(harmony):=20=E5=8F=8C=E5=88=97=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E7=82=B9=E5=87=BB=E5=9B=BE=E7=89=87=E7=AD=89?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E8=BF=9B=E5=85=A5=E5=95=86=E5=93=81=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/mescroll/my-list-mescroll.vue | 8 ++++++++ pages_goods/list.vue | 8 +++----- pages_goods/public/js/list.js | 22 ++++++++-------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/components/mescroll/my-list-mescroll.vue b/components/mescroll/my-list-mescroll.vue index d48279f..d0d2935 100644 --- a/components/mescroll/my-list-mescroll.vue +++ b/components/mescroll/my-list-mescroll.vue @@ -144,6 +144,14 @@ export default { }, listenRefresh() { this.$emit('listenRefresh', true); + }, + /** + * 主动重建 slot DOM。 + * 鸿蒙下通过 :key 变化重建的 .goods-item 元素 @click 事件绑定会丢失, + * 通过自增 listSlotKey 走 slot 重建路径可恢复事件绑定。 + */ + forceSlotRebuild() { + this.listSlotKey = (this.listSlotKey || 0) + 1; } } }; diff --git a/pages_goods/list.vue b/pages_goods/list.vue index 4c93212..1e0f8b9 100644 --- a/pages_goods/list.vue +++ b/pages_goods/list.vue @@ -47,7 +47,7 @@ - + @@ -97,10 +97,8 @@ - - - + diff --git a/pages_goods/public/js/list.js b/pages_goods/public/js/list.js index e9fd52b..137c5fd 100644 --- a/pages_goods/public/js/list.js +++ b/pages_goods/public/js/list.js @@ -298,6 +298,14 @@ export default { }, changeListStyle() { this.isList = !this.isList; + // 鸿蒙下 isList 切换导致 :key 变化、DOM 重建,重建出来的 .goods-item @click 事件绑定会丢失 + // 主动触发 slot 重建,把事件绑定带回来 + // #ifdef MP-HARMONY + const mescroll = this.$refs.mescroll; + if (mescroll && typeof mescroll.forceSlotRebuild === 'function') { + mescroll.forceSlotRebuild(); + } + // #endif this.waterfallflow(0); }, //筛选点击 @@ -489,20 +497,6 @@ export default { }, genNonDuplicate(len = 6) { return Number(Math.random().toString().substr(3, len) + Date.now()).toString(36); - }, - /** - * 鸿蒙下双列 items 一直在 display:none 状态下渲染,首次切换时尺寸测量不对导致瀑布流错位 - * 通过 :key 加 isList 前缀,切换模式时强制重建 DOM,新 DOM 在可见状态下生成,测量正确 - * H5/微信不受影响,走原 item.id - */ - goodsItemKey(item) { - // #ifdef MP-HARMONY - return (this.isList ? 's-' : 'd-') + item.id; - // #endif - - // #ifndef MP-HARMONY - return item.id; - // #endif } } } \ No newline at end of file