From eee351da2a7b1218544b15ff4bbc8bf2992d8cc5 Mon Sep 17 00:00:00 2001 From: fennghuang <89014758+fennghuang@users.noreply.github.com> Date: Tue, 24 Oct 2023 03:09:17 +0000 Subject: [PATCH] fix(collapse): fix getBoundingClientRect --- src/collapse/collapse-panel.vue | 41 ++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/collapse/collapse-panel.vue b/src/collapse/collapse-panel.vue index 68bf8d35a..a1a87a70a 100644 --- a/src/collapse/collapse-panel.vue +++ b/src/collapse/collapse-panel.vue @@ -93,30 +93,39 @@ export default defineComponent({ const headRef = ref(); const wrapperHeight = ref(''); const updatePanelState = () => { - if (!wrapRef.value) { - return; - } - const { height: headHeight } = headRef.value.getBoundingClientRect(); - if (!isActive.value) { - wrapperHeight.value = `${headHeight}px`; - return; - } - const { height: bodyHeight } = bodyRef.value.getBoundingClientRect(); - const height = headHeight + bodyHeight; - wrapperHeight.value = `${height}px`; - }; - - watch(isActive, () => { nextTick(() => { - updatePanelState(); + if (!wrapRef.value) { + return; + } + const { height: headHeight } = headRef.value.getBoundingClientRect(); + if (!isActive.value) { + wrapperHeight.value = `${headHeight}px`; + return; + } + const { height: bodyHeight } = bodyRef.value.getBoundingClientRect(); + const height = headHeight + bodyHeight; + wrapperHeight.value = `${height}px`; }); + }; + + watch( + isActive, + () => { + nextTick(() => updatePanelState()); + }, + { + immediate: true, + }, + ); + + watch(panelContent, () => { + nextTick(() => updatePanelState()); }); onMounted(() => { if (parent?.defaultExpandAll) { updatePanelValue(); } - updatePanelState(); }); return {