1
1
import 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' ;
3
12
import addEventListenerWrap from '../vc-util/Dom/addEventListener' ;
4
13
import { getOffset } from '../vc-util/Dom/css' ;
5
14
import classNames from '../_util/classNames' ;
@@ -22,11 +31,22 @@ export default defineComponent<StickyScrollBarProps>({
22
31
emits : [ 'scroll' ] ,
23
32
setup ( props , { emit, expose } ) {
24
33
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
+ } ) ;
30
50
31
51
const scrollBarRef = ref ( ) ;
32
52
@@ -100,6 +120,7 @@ export default defineComponent<StickyScrollBarProps>({
100
120
isHiddenScrollBar : false ,
101
121
} ) ) ;
102
122
}
123
+ instance . update ?.( ) ;
103
124
} ;
104
125
105
126
const setScrollLeft = ( left : number ) => {
0 commit comments