Challenges with Vue Infinite Loading when multiple requests are made upon page initialization

I have integrated Vue Infinite Loading into my Laravel App to handle data display. The issue I am encountering is that the data is being requested upon page load, even when no scrolling is done. As far as I know, it should only load new data when the scroll reaches the bottom of the page. Here is a snippet of my code:

<infinite-loading :on-infinite="onInfinite" spinner="spiral" ref="infiniteLoading">
    <span slot="no-more"></span>
</infinite-loading>

import InfiniteLoading from 'vue-infinite-loading';

export default {
    components: {
        InfiniteLoading,
    },
    data() {
        return {
            leagueLeaders: [],
            playerStats: [],
            pagination: 1,
        }
    },
    methods: {
        onInfinite() {
            let self  = this;
            axios.get(config.NBLAPI + config.API.PLAYERSTATS2, {
                params: { 
                    page: self.pagination,
                }
            }).then( (response) => {
                let data = response.data.data;
                let lastpage = response.data.last_page;

                if ( response.status == 200 && data.length > 0) {
                    self.leagueLeaders = self.leagueLeaders.concat(data);
                    self.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded');
                    if(self.pagination <= lastpage){
                        self.pagination += 1;
                    }
                }
                else {
                    self.$refs.infiniteLoading.$emit('$InfiniteLoading:complete');
                }
            });
        },
    },
    mounted() {

    }
}

Answer №1

I encountered a similar issue and managed to identify the root cause on my own. When the first page of search results doesn't completely fill the designated UI container, Vue Infinite Loading will automatically paginate until it does. This led to unnecessary additional page loads upon initial loading when I had not provided enough data to populate the container initially. By utilizing developer tools to adjust the size of the UI element so that it was filled upon initial load, the issue was resolved and the functionality worked as intended. Hopefully this insight proves useful!

Answer №2

Resolved the issue by eliminating the overflow:hidden; property from the parent container

Answer №3

This particular behavior occurs because, following your initial request, you triggered the loaded event

self.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded');
before all of your data had been fully displayed on the page.

Because the data had not completely appeared yet, there was empty space left which led the vue-infinite-loading to believe that more requests were necessary.

To avoid this issue, one simple solution is to delay the triggering of

self.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded');
for a few seconds using the setTimeout() function in order to ensure that your data has been rendered entirely on the page.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps to resolve the problem with dynamically generated text fields in Angular

For my current project, I'm implementing Angular and working with a JSON object that looks like this: items={"departure":"New York","arrival":"California","stations":[{"station":"toto"},{"station":"titi"},{"station":"tata"}]} I attempted to display ...

MongoDB has encountered an issue where it is unable to create the property '_id' on a string

Currently, I am utilizing Node.js and Express on Heroku with the MongoDB addon. The database connection is functioning correctly as data can be successfully stored, but there seems to be an issue with pushing certain types of data. Below is the database c ...

What is the best way to calculate the percentage of a quantity within the <td> tag?

I am trying to calculate the percentage of quantity per day by summing up all quantities and then dividing each quantity by the total sum. However, when I combine these calculations in my HTML code using distributed.Quantity, I end up with a NaN value. How ...

The Angular web application utilizing an ASP.NET Web API that is hosted on AppHarbor is showing the incorrect webpage

Working on a web application using Angular and ASP.NET Web API in Visual Studio 2015 has been quite the journey for me. Upon running the solution in VS2015, I encountered two tabs opening in Chrome - one for my Angular client-side application and another ...

Disable page scrolling after making changes to the DOM

When my JavaScript function executes on page load and at set intervals, it cycles through images supplied by another PHP script. However, every time the function manipulates the DOM, the page scrolls back to the top of the containing div, which is quite fr ...

Difficulty encountered when applying date filtering on a specific filter in the MUI-DataGrid

Software Version: "@mui/x-data-grid": "^6.2.1" I have a script that generates columns for the DataGrid as shown below (only including relevant code) if (prop === "date" || prop === "dateModified" || prop === "n ...

A comprehensive guide on implementing router-links in Vue.js

As someone new to laravel-vue, I encountered an issue with router-link while trying to display data from the database. Everything seemed to be working fine until I tried setting the path for the router link, which resulted in it not functioning properly. ...

Creating a JSON object from text using JavaScript is a straightforward process

Looking to generate an object using the provided variable string. var text ='{"Origin":"Hybris","country":"Germany","Email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfem ...

What is the best way to display line breaks that are included within a string?

My strings with line breaks are currently rendering as <br> instead of actual line breaks. I attempted to use back-ticks but that did not work. Is there an easy way to display line breaks on the page without making significant changes to my code? H ...

Troubleshooting issue with .addClass in jqLite within Angular.js

I've been struggling recently to figure out why I can't use the .addClass method on jqLite. element.addClass('active') I have confirmed that element returns an array of HTML elements, and I have tested this multiple times. It's s ...

Click text when using the Google Tag Manager - gtm.click {{Click Text}}

I have a list of shops with detailed information like opening hours and phone numbers. When a user clicks on the shop's name, I want the relevant details to appear using javascript. I am trying to capture the shop's name (SHOP NAME) when a user ...

Can you identify a way to determine in which parent window your child was opened?

I am facing an issue where I have a component being utilized as a child component in two different places. I am trying to implement a back button that directs the user to the correct route depending on the parent component. Currently, I can achieve this wi ...

Incorporating User Information into the Socket with NestJS Guard

Struggling to add a user's data to a socket in order to access it in a Gateway's handlers. Here is my attempted code: @Injectable() export class MySocketAuthGuard implements CanActivate { canActivate(context: ExecutionContext): boolean | Promise ...

When using array.filter(), falsey values are excluded in a function expression, however, they are not excluded when using an arrow function

Currently, I'm tackling a challenge that involves the array_diff function, which aims to retrieve values from array a that also exist in array b. Having recently learned about the advantages of named function expressions for console debugging over an ...

I'm currently working on developing a CPS tester, but have encountered a few challenges along the way

All of the text remains aligned to the left, despite my attempts to position it at the top. I feel like I haven't even completed 1% of the task and I'm faced with countless issues. Although I've coded it so that every click should incremen ...

Is there a way to configure a Mui textfield to only allow numeric input? It currently accepts numbers, the letter "e," and dashes

Take a look at my current code. <TextField error={values[1].error} fullWidth id="id" type="number" value={values[1].Id} placeholder='Enter ID' onChange={handleChange(1,'Id')} variant="outlined" inputProps={{min: 0,inputMode: &apos ...

Steps for accessing a file using HTML form input data:

I have a unique setup with two distinct fields featuring drop-down lists - one for selecting a User and the other for choosing Data. Additionally, I've included a button that is intended to serve as an output based on the selected options from the dro ...

When refreshing a page in Next.js, the loading indicator does not properly turn off

I'm currently working on my portfolio using next.js and I have implemented a 'loading' state to prevent displaying partially loaded gallery images. The 'loading' state should turn off (set to 0) once all the photos are fully loaded ...

Upon launching the Selenium test, the default page that is opened is the Chrome settings

As a newcomer to the world of test automation, I am currently honing my skills with Selenium. Having experimented with Selenium Chrome Webdriver in C#, I have encountered an issue. When executing tests, the settings page keeps opening as the default tab i ...

Encountered an issue while executing Jest test with vuejs-datepicker

Currently, I am diving into the world of Jest while testing my Vue application. Everything was going smoothly until I encountered an issue with one of my components that utilizes vuejs-datepicker. Whenever I run the tests below, I consistently encounter an ...