Skip to content

Commit

Permalink
fix: 请求数据增加底部缓冲
Browse files Browse the repository at this point in the history
  • Loading branch information
wu529778790 committed Jun 8, 2024
1 parent c0b5272 commit 480dadb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/client/views/index/components/VitualList/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</template>

<script setup>
import { ref, computed, onBeforeMount } from "vue";
import { ref, computed, onBeforeMount, watch } from "vue";
const props = defineProps({
data: {
Expand Down Expand Up @@ -76,13 +76,26 @@ onBeforeMount(() => {
const startOffset = ref(0);
const emit = defineEmits(["scrollToBottom"]);
let hasFired = ref(false);
watch(
() => props.data,
() => {
hasFired.value = false;
}
);
const onScroll = (e) => {
const { scrollTop, clientHeight, scrollHeight } = e.target;
startIndex.value = Math.floor(scrollTop / props.itemHeight);
endIndex.value = Math.min(startIndex.value + count.value, props.data.length);
startOffset.value = scrollTop - (scrollTop % props.itemHeight);
// 如果滚动到底部
if (scrollTop + clientHeight === scrollHeight) {
if (
props.buffer * props.itemHeight >=
scrollHeight - (scrollTop + clientHeight) &&
!hasFired.value
) {
hasFired.value = true;
console.log("到底了");
emit("scrollToBottom");
}
};
Expand Down

0 comments on commit 480dadb

Please sign in to comment.