vueuse / vueuse

Collection of essential Vue Composition Utilities for Vue 2 and 3
https://vueuse.org
MIT License
19.74k stars 2.49k forks source link

useInfiniteScroll Infinite loop #4000

Open kingwrcy opened 3 months ago

kingwrcy commented 3 months ago

Describe the bug

I haven't started scrolling the scroll bar yet, but it keeps calling the function onLoadMore in an infinite loop. The code is copied from the demo of the official website.

Reproduction

https://stackblitz.com/edit/vitejs-vite-jcnxvx?file=src%2FApp.vue

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vueuse/components: ^10.10.0 => 10.10.0 
    @vueuse/core: ^10.10.0 => 10.10.0 
    vue: ^3.4.27 => 3.4.27

Used Package Manager

npm

Validations

RandallAnjie commented 3 months ago

You need to add height and overflow attributes to the outer div to ensure that the page has enough space for scrolling

<div style="height: 400px; overflow: auto;" v-infinite-scroll="[onLoadMore, { distance: 10 }]">
    <div v-for="item in data" :key="item">
      {{ item }}
    </div>
  </div>

It seems that the examples on the official website do not add these two attributes.

andrewvasilchuk commented 2 months ago

I believe this behavior is expected. Even if you don't scroll, the callback will still be triggered to fetch more items and fill the remaining height.

The reproduction link you provided does not contain a valid example of the issue.

FacundoBrum16 commented 9 hours ago

i have the same issue, It makes me feel insecure