fix(harmony): 数据加载后通过改变 slot key 强制重建列表 DOM

- 根因:鸿蒙 ArkUI 对 slot 内 Vue 响应式更新完全失效
- 之前方案(:class/:style/v-if/)都只能影响 slot 内部,ArkUI 不响应
- 新方案:slot 外包一层 view 绑定动态 key,数据加载后 300ms 自增 key
- key 变化强制 Vue 重建整个 slot 子树,完全绕过 ArkUI 响应式限制
- 还原之前无效的 mounted 延迟方案
This commit is contained in:
2026-06-05 11:36:28 +08:00
parent cbbb1e0327
commit dc2018ee17

View File

@@ -15,7 +15,9 @@
@init="mescrollInit"
>
<!-- 数据列表 -->
<slot name="list"></slot>
<view :key="'slot-' + renderSlotKey">
<slot name="list"></slot>
</view>
</mescroll>
</template>
@@ -45,6 +47,7 @@ export default {
onScroll: true
},
scrollY: 0,
renderSlotKey: 0,
isInit: false
};
},
@@ -72,17 +75,8 @@ export default {
this.isInit = true;
},
mounted() {
// #ifdef MP-HARMONY
// 鸿蒙 ArkUI DOM 初始化较慢,延迟加载确保渲染管线就绪
setTimeout(() => {
this.mescroll.resetUpScroll();
this.listenRefresh();
}, 400);
// #endif
// #ifndef MP-HARMONY
this.mescroll.resetUpScroll();
this.listenRefresh();
// #endif
},
methods: {
// mescroll组件初始化的回调,可获取到mescroll对象
@@ -101,6 +95,12 @@ export default {
upCallback() {
//联网加载数据
this.$emit('getData', this.mescroll);
// #ifdef MP-HARMONY
// 鸿蒙 ArkUI 对 slot 内容响应式更新不敏感,数据加载后通过改变 key 强制重建
setTimeout(() => {
this.renderSlotKey++;
}, 300);
// #endif
},
//点击空布局按钮的回调
emptyClick() {