From a298b00052228eae3017f20ece6e26f0b1d2e02f Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Wed, 30 Mar 2022 23:15:42 +0800 Subject: [PATCH] fix: sticky scrollbar show when init --- components/vc-table/stickyScrollBar.tsx | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/components/vc-table/stickyScrollBar.tsx b/components/vc-table/stickyScrollBar.tsx index 4a3dfd2f9..93d645fac 100644 --- a/components/vc-table/stickyScrollBar.tsx +++ b/components/vc-table/stickyScrollBar.tsx @@ -13,7 +13,10 @@ interface StickyScrollBarProps { onScroll: (params: { scrollLeft?: number }) => void; offsetScroll: number; container: HTMLElement | Window; - scrollBodySizeInfo: { scrollWidth: number; clientWidth: number }; + scrollBodySizeInfo: { + scrollWidth: number; + clientWidth: number; + }; } export default defineComponent({ @@ -40,7 +43,7 @@ export default defineComponent({ const [scrollState, setScrollState] = useLayoutState({ scrollLeft: 0, - isHiddenScrollBar: false, + isHiddenScrollBar: true, }); const refState = ref({ @@ -135,13 +138,17 @@ export default defineComponent({ onResizeListener = addEventListenerWrap(window, 'resize', onContainerScroll, false); }); - watch( - [scrollBarWidth, isActive], - () => { - onContainerScroll(); - }, - { immediate: true }, - ); + onMounted(() => { + setTimeout(() => { + watch( + [scrollBarWidth, isActive], + () => { + onContainerScroll(); + }, + { immediate: true, flush: 'post' }, + ); + }); + }); watch( () => props.container,