From edbe96aa8fc0857e6887ff2ccf613ec8470c2260 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Fri, 11 Mar 2022 15:01:59 +0800 Subject: [PATCH] fix(app): triggered component Rebuild when removeUniChild question/140609 --- .../src/view/framework/dom/components/UniComponent.ts | 4 ++++ .../src/vue/picker-view-column/index.tsx | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts b/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts index c268aaa89b..9020e5a3b4 100644 --- a/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts +++ b/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts @@ -192,6 +192,10 @@ export class UniContainerComponent extends UniComponent { queuePostActionJob(this.getRebuildFn(), JOB_PRIORITY_REBUILD) return super.insertBefore(newChild, refChild) } + removeUniChild(node: UniNode) { + queuePostActionJob(this.getRebuildFn(), JOB_PRIORITY_REBUILD) + return super.removeUniChild(node) + } rebuild() { // 刷新容器组件状态 if (__DEV__) { diff --git a/packages/uni-components/src/vue/picker-view-column/index.tsx b/packages/uni-components/src/vue/picker-view-column/index.tsx index 932c462ddd..4abb5de65c 100644 --- a/packages/uni-components/src/vue/picker-view-column/index.tsx +++ b/packages/uni-components/src/vue/picker-view-column/index.tsx @@ -251,11 +251,15 @@ export default /*#__PURE__*/ defineBuiltInComponent({ } if (__PLATFORM__ === 'app') { + let isMounted: boolean = false useRebuild(() => { state.length = (contentRef.value as HTMLElement).children.length - // 由于 App 端 onMounted 时机未插入真实位置,需重新执行 - initIndicatorHeight() - initScroller() + if (!isMounted) { + isMounted = true + // 由于 App 端 onMounted 时机未插入真实位置,需重新执行 + initIndicatorHeight() + initScroller() + } }) } -- GitLab