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

Create an Oval-Shaped Image Cutout

Currently, I have a fabric.JS canvas where objects can be added. However, I am interested in clipping these objects into an oval shape, similar to the clip demos on fabricjs.com. In my current project (JSFiddle), I have been able to crop the object into a ...

PHP live data updating: stay current with real-time data updates

I have a functional API that is currently static, but I want it to update periodically and display live data in my HTML code. I'm not sure where to begin. Should I start with Javascript or Ajax? Any guidance would be greatly appreciated. This is my ...

What are the best practices for implementing jquery owlCarousel within an Angular 4 component?

I've included my 'carousel.js' file like this: $('#owl-carousel-1').owlCarousel({...}); and in carousel.component.html, I have: <div id="owl-carousel-1" class="owl-carousel owl-theme center-owl-nav home- carousel">....< ...

Is there a way to trigger a "click" on a webpage without physically clicking? So that I can preview the response message before actually clicking

Is it possible to generate a "mock" request to a server through a website in order to examine the response before sending the actual request? Let me clarify with an example: if I were to click on a button on a website, it displays a certain message. I am ...

Simulating a JavaScript constructor using Sinon.JS

I need to write unit tests for the ES6 class below: // service.js const InternalService = require('internal-service'); class Service { constructor(args) { this.internalService = new InternalService(args); } getData(args) { let ...

The Handsontable popup autocomplete editor is unfortunately truncated by the horizontal scrollbar

I have implemented an autocomplete feature on all columns in my project. However, I am facing an issue where the autocomplete editor gets cut off by the horizontal scrollbar. You can see the problem demonstrated in this jsfiddle link. Here is some code re ...

Having issues with my custom AngularJS directive functionality

app.directive("myData", function() { return { templateUrl: '/my-data.html' }; }); my-data.html file code <tr ng-repeat="employee in employees"> <td>{{employee.id}}</td> <td>{{employee.name}}</t ...

Having trouble with a jQuery.validationEngine reference error?

Despite everything being correctly referenced, I am facing difficulties in getting it to function properly. It's strange because it worked once, but the validation message took 10 seconds to appear. After that, without making any changes, I tried agai ...

"We encountered an error with the external script while trying to load file content using jQuery's ajax function. It

//C.php <script type="text/javascript"> $(document).ready(function(e) { $('div').load("D.php"); }); </script> <div></div> //D.php <script type="text/javascript" src="D.js"></script> //D.js console.log(45 ...

Creating a hierarchical tree structure using the v-for directive by incorporating parentid and order properties

I am attempting to create a structure resembling the one depicted below from the given state: state: { appbar: [{ name: "Section 1", // Name of element order: 1, //Define order, not used yet parenti ...

What is the best way to implement CSS rules for a hidden submenu?

Can anyone help me figure out how to apply CSS rules for a hidden submenu? I've attempted to use some JavaScript, but it's not working as expected. Below is a sample of the code I'm working with. The idea is that when you click on the anchor ...

The Typescript compiler will continue to generate JavaScript code even if there are compilation errors

As a fresh learner of TypeScript, I have been experimenting with some basic concepts. Below is the code from my file app1.ts: class Monster { constructor(name, initialPosition) { this.name = name; this.initialPosition = initialPosition ...

Configuring a Selenium Firefox profile

While performing our tests, we came across an issue with how FireFox handles events when the browser is not in focus. We discovered that this problem can be resolved by setting up a FireFox profile with the preference "focusmanager.testmode" set to true ( ...

What occurs when the update function returned by React.useState() is invoked?

Just recently, I delved into the world of React hooks and decided to implement a small feature using them. The feature enables hidden texts to be displayed when users click on hyperlinks. Although I managed to make the code work, it appears that there are ...

When using JQuery's :first selector, it actually chooses the second element instead of the first

I'm facing an issue with a JQuery script that makes an AJAX request to the following URL https://djjohal.video/video/671/index.html#gsc.tab=0, which holds information about a video song. My goal is to extract and retrieve all the details from the HTM ...

Convert your Airbnb short link into the full link

I am currently developing an application that utilizes Airbnb links as part of its input. So far, I have identified two types of links: Long form, for example: . These are commonly used on desktop. Short form, such as: . These shorter links are often shar ...

What is the method for accessing an image in JavaScript?

Currently, I am developing a currency converter for a gaming marketplace and I would like the users to be able to generate images using JavaScript. While most of the work is completed, I am facing an issue where the images are not displaying properly and i ...

Exploring VueJS templating: Loading external templates

Being new to Vue.js, I have some experience with AngularJS where we used to load templates like this: template: '/sometemplate.html', controller: 'someCtrl' My question is how can we achieve something similar in Vue? Instead of embeddi ...

AngularJS: Triggering events in one controller to update data in another controller

I've tried several examples, but I'm not getting the expected results. In my project, I have two controllers - one for a dropdown and one for a table. When a user selects an item from the dropdown, a factory triggers a get request to update the t ...

Exploring the Efficiency Enhancements in the next/image Optimization Process within Next.js

I've been delving into Next.js and using the next/image component for image rendering. While leveraging it to enhance image loading in my project, I've become intrigued by the intricate workings behind the scenes. I'm particularly interested ...