Laravel vue infinite scroll failing to load additional content

I've been trying to implement the infinite scroll feature from Element UI in my app, but for some reason, it's just not working. Here's a snippet of my code:

Code

script

// Your JavaScript code goes here
            // Make sure you have imported Axios for API calls
        

HTML

<div class="row mt-5 my-5 infinite-list" v-infinite-scroll="load" infinite-scroll-disabled="disabled">
            <div class="col-md-3 mb-3" v-for="product in products" :key="product.slug" :offset="1">
                <el-card shadow="hover" :body-style="{ padding: '0px' }">
                    {{product.name}}
                </el-card>
            </div>

            <div class="col-md-12 mt-3" v-if="loading">
                <el-card shadow="always" class="text-center">Loading...</el-card>
            </div>
            <div class="col-md-12 mt-3" v-if="noMore">
                <el-card shadow="always" class="text-center">That's it, No more!</el-card>
            </div>
        </div>
        

Meta data

Your meta data link goes here

Result

Link to your result image

Any idea what could be going wrong with my implementation?

Answer №1

it seems like the issue lies within your load function, let's take a closer look at it.

 load () {
    this.loading = true
    setTimeout(() => {
        this.count += this.perPage // adding 8 more to the page
        this.loading = false
    }, 1000)
  },

the timeout of 1000 ms in your load function is causing some timing issues. Instead of setting this.loading to false after 1000 ms, consider setting it to false upon successful completion of the fetch call. The same goes for updating this.count. Hope this insight helps you resolve the issue.

EDIT:

your revised load function should be like the following

load () {
this.loading = true
this.getProducts(); // calling getProducts each time load is triggered
},

and your fetch function should resemble the code below

getProducts: function(){
    axios.get('/api/products').then(response => {
        this.products = response.data.data;
        this.count += this.perPage 
        this.loading = false
        this.perPage = response.data.meta.per_page; 
        this.total = response.data.meta.total; 
    }).catch((err) => console.error(err));
}

consider using getProducts instead of load and removing the load function entirely. Set this.loading=true within your getProducts function. Previously, getProducts was only called once during component mounting, but now it needs to be triggered every time a load more action is requested.

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

SweetAlert2 not displaying properly in Ionic6 - troubleshooting the issue

My current project is an Ionic 5 Angular project with SweetAlerts2 popups. Recently, I decided to upgrade to Ionic6 and encountered an issue where the SweetAlerts2 popups are not displaying correctly. The alert seems to only show up in the header, leaving ...

Error in Module Building: The path argument must be a string type. A different type was received, which caused the build to fail

I recently updated my Vuetify version from 1.5 to the latest 2.3.10. However, when trying to run the webpack server, I encountered this error message. Even after adding yarn add sass -D, the issue persists. Can someone please assist me in resolving this pr ...

Break down the text of a paragraph into separate words, placing each word within its own span element, and then add animations

I am facing an issue with my paragraph element that has the display property set to hidden. I have split each word of the paragraph and placed them inside individual span elements. My goal is to create an effect where each word comes from different locatio ...

How can you toggle the visibility of a text based on the selection of a jQuery radio button?

Is it possible to dynamically enable or disable a field based on the selection of a radio button? Here are the rules: The field should only be active when the "Inactive" radio button is selected Check out the code snippet below for reference: Radio B ...

Guide on how to incorporate an external homepage into a quasar/cordova/vue.js mobile application

I have a mobile application built with quasar/cordova/vue.js that I am working on. I want to incorporate a feature where users can browse through an online catalog. Currently, I am using the inappbrowser plugin, which opens the website in full screen mode ...

The onclick event in JavaScript is unresponsive on mobile devices

Our website is powered by Opencart 1.5.6.4 and the code snippet below is used to add items to the shopping cart. <input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?&g ...

Troubleshooting JavaScript: Dealing with JSON Import Issues Involving Arrays of Objects

I'm encountering an issue while trying to import a JSON file that contains an array of blog-posts. Although all the data from the JSON file is successfully imported, I am facing troubles with accessing the Array of objects (edges). This specific code ...

Retrieve file server domain using JavaScript or jQuery

I'm trying to extract the domain name without the "http(s)://www." from a file link. For example, if the script returns "example.com", I want it to parse through links like "http://www.example.com/file.exe" or "https://example.com/folder/file.txt#some ...

Sending an identifier to a PHP file using JavaScript

I am facing an issue with my JavaScript code where the id is supposed to be passed to my PHP script at intervals, but if the id stops being passed (indicating that the user has closed the JavaScript page), a specific block in the if statement should run in ...

JavaScript, PHP handlers, and CommentBox all work together seamlessly to create

$("#login").click(function(){ $.getJSON("handlers/Login.php?name="+$("#username").val(), function(data){ console.log(data); //retrieves data from login box and sends it to the handler, returning a JSON array }); template = $("#hid ...

Is there a way to alter a class using ng-class only when the form is deemed valid?

I am trying to implement a feature where an input field shows as required, but once the user enters text, it indicates that the input is valid by changing the border color from red to green. I am facing an issue with this line of code always returning fal ...

Angular.js: The $setDirty() method on a form does not automatically affect its child form elements

Currently, I am working on a form validation project using Angular.js. A specific challenge that I am facing is setting the dirty state on a child element of a form in an isolated scope within a directive. Does anyone know how to achieve this and set the i ...

Exploring the use of Rails and jQuery to automatically update data through the use of setTimeout and ajax calls

There's a specific page accessible in the browser at "/calendar" that directs to "calendar#index". Utilizing a javascript setTimeout function, I'm attempting to re-fetch and update data on my page using $.get ajax method. $.get("<%= calendar ...

Is it possible for jquery.find() to only target immediate children?

How can I use jQuery.find() to specifically target only the direct children of an element without selecting their descendants? Leading the selector with '>' or using '*' doesn't give me the desired result. While I know about jQuer ...

HTML elements generated dynamically do not possess any jQuery properties

I have implemented a draggable list of Div elements using jQuery. Here is the code: <div id="external-events"> <h4>List Of Staffs</h4> <div class="external-event" data-id="1">Name</div> //Draggab ...

Deciphering JavaScript script within a Node.js module

// =============================================================================== // Auth // =============================================================================== const admin = require('firebase-admin'); //what happens if i move th ...

Using third-party libraries like jQuery, CSS, and JavaScript in your React project by directly importing them into the index.html file can be a more efficient approach compared

When working with React, is it advisable to import external JavaScript, jQuery, and CSS files into the index.html file in the public folder? Are there any potential performance implications associated with this practice? I have utilized some jQuery functi ...

Updating Variables Declared in Parent Component from a Child Component in React using NextJS - A Comprehensive Guide

After reviewing the tutorial on React: Reverse Data Flow to update the variables foodObj, input, and buttonClicked declared in the Parent Component file Main.js, using the child component <SearchAndSuggestion>, I encountered an issue. Here is a snipp ...

I am looking to grasp the concept of the Conditional ternary statement

I attempted to convert the code below into a ternary operator, but unfortunately ended up with an undefined result. Could someone please clarify where I made a mistake and advise on how to correct it properly? Thanks in advance. const plantNeedsWater = f ...

Every day, I challenge myself to build my skills in react by completing various tasks. Currently, I am facing a particular task that has me stumped. Is there anyone out there who could offer

Objective:- Input: Ask user to enter a number On change: Calculate the square of the number entered by the user Display each calculation as a list in the Document Object Model (DOM) in real-time If Backspace is pressed: Delete the last calculated resul ...