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