Description
Version
2.4.5
Vue.js version
2.6.11
Description
I'm trying to use Vue infinite loading with a native, body scroll of the browser as presented in this demo.
The problem is that the data is loaded partially, but also recursively - what I mean is that on page load, even when I don't try to scroll, the infinite handler is triggered and it fetches the next data, but should not.
The afterwards logic calls $state.complete() after it fetches all the items, so it stops there.
Reproduction Link
<infinite-loading
v-if="showInfinite"
force-use-infinite-wrapper=".__xd"
@infinite="handleInfiniteLoader"
>
<div slot="no-more"></div>
<div slot="no-results"></div>
</infinite-loading>
The handler:
async handleInfiniteLoader($state: {
loaded: () => any;
complete: () => any;
}) {
const results = await this.load();
console.log("results", results);
if (results.length > 0) {
$state.loaded();
} else {
$state.complete();
}
},
BTW it loads 25 items at first, to avoid triggering infinite loader right after the first load. Meaning I'm filling the whole page with items; then only scrolling down should trigger the handler.
Also, what I tried - I thought the infinite loader is visible at first screen paint and that's why it's recursively triggering the handler.
So I tried to load some items on component mounted and wrap infinite-loader inside v-if
statement, only to make infinite-loader being rendered after the page is filled with 25 results (meaning infinite loader would render for the first time at the very end of the page, being not visible in the viewport).
Steps to reproduce
I cannot make a demo to reproduce the issue today and I think the description I gave is fair enough. I will try to make a demo tomorrow if needed.
What is Expected?
The infinite handler should be fired when scrolling actually makes infinite-loading component be visible in the viewport.
What is actually happening?
The infinite handler is triggered recursively until all the data is fetched, even without doing any "scroll" at all.