Skip to content

Commit 0a5dbf3

Browse files
committed
fix: virtual scrollBar not update, close #5124
1 parent efa045a commit 0a5dbf3

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

components/vc-table/stickyScrollBar.tsx

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
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';
312
import addEventListenerWrap from '../vc-util/Dom/addEventListener';
413
import { getOffset } from '../vc-util/Dom/css';
514
import 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

Comments
 (0)