Send a GET request to the API with an incremented value in the last parameter

Currently, I'm facing an issue with accessing data using pagination and lazy loading. The pagination system works fine for the first request, but the last parameter increment at the end of the page is not functioning as expected. For instance, when I try to change the last parameter at the end of the page from to and so on, the system fails to respond correctly. I've experimented with various methods to increment the parameter but haven't had any success.

new Vue({

  el: "#app",
  data: {
    posts: [],
    limit: 8,
    busy: false
  },
  methods: {
    loadMore() {


      console.log("Adding 8 more data results");
      this.busy = true;
      axios.get("http://features.domain_server.com/mobileapi/eggsrate/1/0").then(response => {
        const append = response.data.slice(
          this.posts.length,
          this.posts.length + this.limit
        );
        this.posts = this.posts.concat(append);
        this.busy = false;
      });

    },

  },
  created() {
    this.loadMore();
  }
});
AOS.init();
<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>Egg Rates</title>
  <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css'>
<link rel='stylesheet' href='https://unpkg.com/aos@next/dist/aos.css'>

</head>
<body>
<!-- partial:index.partial.html -->
<section class="section">
  <div id="app">
    <ul>
      <div v-infinite-scroll="loadMore" infinite-scroll-disabled="busy" infinite-scroll-distance="limit">
        <li v-for="post in posts" style="margin-bottom: 2rem;" data-aos="slide-up" data-aos-offset="100" data-aos-easing="ease-out-back">
          <div class="card">
            <header class="card-header">
              <p class="card-header-title">
                {{post.id}}
              </p>
            </header>
            <div class="card-content">
              <div class="content">
                <p>{{post.name}}</p>
                <p>{{post.cities}}</p>
              </div>
            </div>
          </div>
        </li>
      </div>
    </ul>
  </div>
</section>
<!-- partial -->
  <script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.8/vue.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js'></script>
<script src='https://unpkg.com/aos@next/dist/aos.js'></script>
<script src='https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f0868585dd999e96999e998495dd8293829f9c9cb0c2dec0dec2">[email protected]</a>/vue-infinite-scroll.js'></script>
<script  src="./script.js"></script>

</body>
</html>

Answer №1

Aside from all other factors, the main thing to focus on is keeping a record of the current page and increasing it when loading more content.

data: () => ({
  posts: [],
  limit: 8,
  busy: false,
  page: 0 // 👈 this is a new addition
}),

Also, in the loadMore() function:

axios.get(`http://features.domain_server.com/mobileapi/eggsrate/1/${this.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

Using angularJS and Regular Expressions to eliminate the "+" symbols in an email address

I have been given the task of disallowing email addresses with a "+" sign from registering. As someone new to regex, my understanding is that it is better to focus on defining what constitutes a valid input rather than listing what should be excluded. I re ...

When using Angular, automatically shift focus to the next input field by pressing the

I am faced with a challenge involving multiple editable inputs on my screen. Alongside these editable inputs, there are buttons and disabled inputs present. The current behavior is such that when I press Tab, the focus shifts to the HTML elements between ...

Create a three-dimensional tree array in Typescript/Javascript by transforming a flat array

Received data is structured as follows: const worldMap = [ { "name": "Germany", "parentId": null, "type": "Country", "value": "country:unique:key:1234", "id&qu ...

The error ElementNotVisibleError occurs in Selenium::WebDriver when attempting to use the send_key function with a Chrome browser, as the element is not currently visible

A problem has arisen with the Ruby Selenium script I am running in parallel. The issue occurs when attempting to send text input through send_key on a webpage while using the Chrome browser. Selenium::WebDriver::Error::ElementNotVisibleError: element not ...

Guide to leveraging Bootstrap mixins within VueJS components

I'm currently using vue-cli and bootstrap-vue in my project. I'm facing an issue with bootstrap mixins not working as expected, even though I have imported Bootstrap in my main.js like this: import 'bootstrap/scss/bootstrap-grid.scss' ...

Ways to dismiss a Modal popup instantly without having to wait for an ajax response

I am currently facing an issue with sending email attachments through ajax. The process takes too long to send and close the email modal window. I am looking for a solution where the modal window closes immediately after clicking the send email button, all ...

Vuex Action never returns a resolved value

I'm encountering an issue with getting my Action to resolve the promise properly. I've gone through what appear to be the most relevant posts. Returning Promises from Vuex actions I need to know when my action has finished so that my component ...

What steps should I take to resolve a library add error within my Vue.js project?

I am encountering an issue while trying to install the Vuelidate vue library in my existing project. I have tried using the commands npm install --save vuelidate and npm i vuelidate, but I keep getting the following errors. Can someone please assist me? ...

GetServerSideProps function yielding varied prop values

I'm currently exploring NextJS and delving into SSR. I've been struggling to grasp the functionality of getServerSideProps(). It seems that it should replace useState in order to be rendered on the backend, but I'm receiving different props ...

Issue with Typescript and rxjs 6: Property is not found on type 'object'

Currently, I am working on a small application using Ionic 3 to query a Firebase database for two sets of data. Initially, I encountered an error during the first build stating "Property does not exist on type '{}'", however, after saving the .ts ...

Transforming the mui stepper connection into a progress bar is simple. Each step contains individualized content to guide you through the process

Is there a way to make the MUI stepper connector act as a progress indicator? I have step content and connectors as separate divs, but I'm having trouble styling them. Any assistance would be greatly appreciated! ...

Using ReactJS and react-router to exclude the navigation menu on the login page

I have a LoginPage designed like this: https://i.sstatic.net/yzovV.png After logging in, you will be directed to this page: https://i.sstatic.net/pZFou.png Now, I want the login page to have no navigation and look like this: https://i.sstatic.net/1sH9v ...

The function 'myfunc' was called within a render, however, it is not defined in the instance

I keep seeing this error message Property 'myfunc' was accessed during render but is not defined on instance, and I'm not sure why. Below are my HTML and JavaScript code snippets. const ListRenderingApp = { data() { return { todo ...

Managing simultaneous access to a variable in NodeJS: Best practices

For instance: var i = 0; while(true) http.request('a url', callback_f); function **callback_f**(){ **i++**; } In this straightforward scenario, multiple requests could unintentionally increase the value of i simultaneously. How can I creat ...

Unable to retrieve the accurate scrollHeight value for a textarea in VueJs and Vuetify

Trying to access the scrollHeight value of a textarea field, I encountered an issue when using the document object: document.querySelector("#textarea-element").scrollHeight. The value returned was correct. However, when attempting to retrieve it using refs ...

Transform Ajax response into dropdown menu option

I have made an ajax call and received HTML as a response. Now, I need to convert this output into options and add them to select tags on my webpage. <div class="views-element-container"> <div class="view view-contact-view-id-conta ...

[filepond] in order to enroll using the serverId value received from the server

Using 'filepond' within a Vue application is causing an issue. In the "process" function, the ID value obtained after transferring the file to the server (response.id) needs to be registered as 'serverId' of the file. Upon checking the ...

Sometimes, JQuery struggles to set input values accurately

Exploring the single page app sample provided here, I have encountered some anomalies when attempting to manipulate input controls with JQuery under certain conditions. Below is the consistent HTML structure followed by the JavaScript snippets in question. ...

Ways to identify if the requested image is error-free (403 Forbidden)

One of my scripts loads an image from a specific source every 300 ms, but sometimes it receives a 403 Forbidden response. When this happens, the image element ends up blank. I want to find a way to verify if the image has received a valid 200 response befo ...

Utilize the power of jQuery accordion to organize and display your table

Is there a way to integrate jQuery UI Accordion with an HTML table so that columns can be collapsible? I have tried various methods but haven't been successful. Currently, this is what I have implemented: $(".col1, .col2").addClass("hidden"); $(".s ...