Skip to content

Commit

Permalink
fix(virtual-list): fix the wrong scrolling position of the virtual li…
Browse files Browse the repository at this point in the history
…st (#2665)
  • Loading branch information
Saber-Kurama authored Aug 25, 2023
1 parent 9decb50 commit 5491582
Showing 1 changed file with 11 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,6 @@ export default defineComponent({
buffer,
});
const shouldScroll = ref(true);
const scrollData = reactive({
scrollTop: 0,
scrollHeight: 0,
});
// 数据发生修改
watch(dataKeys, () => {
shouldScroll.value = false;
});
const currentList = computed(() => {
if (props.threshold && data.value.length <= props.threshold) {
return data.value;
Expand All @@ -185,27 +176,17 @@ export default defineComponent({
const onScroll = (ev: Event) => {
const { scrollTop, scrollHeight, offsetHeight } =
ev.target as HTMLElement;
if (shouldScroll.value) {
scrollData.scrollTop = scrollTop;
scrollData.scrollHeight = scrollHeight;
const _start = getStartByScroll(scrollTop);
if (_start !== start.value) {
setStart(_start);
}
emit('scroll', ev);
const bottom = Math.floor(scrollHeight - (scrollTop + offsetHeight));
if (bottom <= 0) {
emit('reachBottom', ev);
}
} else {
// 数据发生修改完成 (是否采用MutationObserver)
if (scrollHeight !== scrollData.scrollHeight) {
shouldScroll.value = true;
setTimeout(() => {
scrollTo(scrollData.scrollTop);
}, 10);
}
scrollTo(scrollData.scrollTop);
const _start = getStartByScroll(scrollTop);
if (_start !== start.value) {
setStart(_start);
nextTick(() => {
scrollTo(scrollTop);
});
}
emit('scroll', ev);
const bottom = Math.floor(scrollHeight - (scrollTop + offsetHeight));
if (bottom <= 0) {
emit('reachBottom', ev);
}
};
Expand Down

0 comments on commit 5491582

Please sign in to comment.