11import type { Ref } from 'vue' ;
2- import { computed , defineComponent , onBeforeUnmount , onMounted , ref , watch } from 'vue' ;
2+ import {
3+ getCurrentInstance ,
4+ onBeforeUpdate ,
5+ onBeforeMount ,
6+ defineComponent ,
7+ onBeforeUnmount ,
8+ onMounted ,
9+ ref ,
10+ watch ,
11+ } from 'vue' ;
312import addEventListenerWrap from '../vc-util/Dom/addEventListener' ;
413import { getOffset } from '../vc-util/Dom/css' ;
514import classNames from '../_util/classNames' ;
@@ -22,11 +31,22 @@ export default defineComponent<StickyScrollBarProps>({
2231 emits : [ 'scroll' ] ,
2332 setup ( props , { emit, expose } ) {
2433 const tableContext = useInjectTable ( ) ;
25- const bodyScrollWidth = computed ( ( ) => props . scrollBodyRef . value . scrollWidth || 0 ) ;
26- const bodyWidth = computed ( ( ) => props . scrollBodyRef . value . clientWidth || 0 ) ;
27- const scrollBarWidth = computed (
28- ( ) => bodyScrollWidth . value && bodyWidth . value * ( bodyWidth . value / bodyScrollWidth . value ) ,
29- ) ;
34+ const bodyScrollWidth = ref ( 0 ) ;
35+ const bodyWidth = ref ( 0 ) ;
36+ const scrollBarWidth = ref ( 0 ) ;
37+ const instance = getCurrentInstance ( ) ;
38+ const updateSomeValue = ( ) => {
39+ bodyScrollWidth . value = props . scrollBodyRef . value . scrollWidth || 0 ;
40+ bodyWidth . value = props . scrollBodyRef . value . clientWidth || 0 ;
41+ scrollBarWidth . value =
42+ bodyScrollWidth . value && bodyWidth . value * ( bodyWidth . value / bodyScrollWidth . value ) ;
43+ } ;
44+ onBeforeMount ( ( ) => {
45+ updateSomeValue ( ) ;
46+ } ) ;
47+ onBeforeUpdate ( ( ) => {
48+ updateSomeValue ( ) ;
49+ } ) ;
3050
3151 const scrollBarRef = ref ( ) ;
3252
@@ -100,6 +120,7 @@ export default defineComponent<StickyScrollBarProps>({
100120 isHiddenScrollBar : false ,
101121 } ) ) ;
102122 }
123+ instance . update ?.( ) ;
103124 } ;
104125
105126 const setScrollLeft = ( left : number ) => {
0 commit comments