Tips on utilizing the b-pagination API?

layoutchange() {

  this.layout = !this.layout;

  if (this.layout === true) {

    this.perPage = this.layout ? 8 : 12;
    this.listProducts();
  } else {

    this.perPage = !this.layout ? 12 : 8;
    this.gridProducts();
  }
},
<a class="list-icon" v-bind:class="{ active: layout == true }" v-on:click="layoutchange"></a>
<a class="grid-icon" v-bind:class="{ active: layout == false }" v-on:click="layoutchange></a>

<ul v-if="layout == true">
  //code for product display
  <b-pagination v-model="currentPage" :total-rows="rows" :per-page="perPage"></b-pagination>
</ul>

<ul v-if="layout == false">
  //code for product display
  <b-pagination v-model="currentPage" :total-rows="rows" :per-page="perPage"></b-pagination>
  </ul

Essentially, my goal is to implement an API call for each page when pagination is used on my website. For example, when a user clicks on page 1 or 2, I want to trigger an API call accordingly. I am currently using the b-pagination component from Bootstrap-Vue, but I am unsure if there is an event that can be utilized to call the API for each page, such as next, previous, or any other relevant event. This way, I can seamlessly integrate API calls with pagination.

I have both grid and list view options, each with their own pagination functionality.

For more information, please refer to the documentation at

Answer №1

In case the b-pagination component does not provide an event that suits your specific use case, you can simply monitor the currentPage property.

For more information, you can refer to https://v2.vuejs.org/v2/guide/computed.html#Watchers

export default {
  data() {
    return {
      currentPage: null,
    }
  },
  watch: {
    currentPage(newVal) {
      if(newVal) {
        // Make an API call
        // Here is an example with a random API endpoint
        const endpoint = 'https://jsonplaceholder.typicode.com/todos/'
        
        fetch(endpoint + newVal).then((res) => {
          console.log(res)
          // Update relevant data
        })
      }
    }
  },
  mounted() {
    // Set the currentPage to your route or default to 1 as an example
    this.currentPage = 1
  }
}

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

"Unlocking the Power of mediaElementjs: Easy Steps to Accessing the Player Instance

I'm facing a small issue with the MediaElement.js player. To access the player instance, I usually use the following code (which works in HTML5 compatible browsers): // Retrieve player this.playerId = $('div#shotlist-player video').att ...

Experiencing a missing handlebars helper error when utilizing a helper within partials in express-handlebars

I have set up custom helpers using express-handlebars like this: const { create } = require("express-handlebars"); // Configuring the handlebars engine const hbs = create({ helpers: require("./config/handlebars-helpers"), }); app.engi ...

What is the best method for purging a previously stored variable from the cache when making an Ajax call and simultaneously passing a

I am encountering an issue with variable loading during the ajax call. Upon clicking, I pass a variable to the ajax call which then sends the value to a PHP script. The data obtained is from: rnc.csv DLRNC01 DLRNC02 DLRNC03 DLRNC04 DLRNC05 DLRNC06 DLR ...

Stop automatic page refresh after submitting a jQuery post request

I've tried various solutions, but unfortunately, neither e.preventDefault() nor return false seem to be working for me. When I use prevent default ajax doesn't make post request. Even using $.post doesn't work as expected. Furthermore, addin ...

Is there a way to use lodash to convert an array into an object?

Below is an array that I am working with: const arr = [ 'type=A', 'day=45' ]; const trans = { 'type': 'A', 'day': 45 } I would appreciate it if you could suggest the simplest and most efficient method to ...

I'm trying to determine which jQuery event would be more beneficial for my needs - should I go with

I'm facing a dilemma On my website, I need to capture the value of a span within a modal. The value changes when the modal is opened and reverts to the old value when closed. This particular value represents the cart total in my online store. Wheneve ...

The information being sent from Angular is not being successfully transmitted to the XAM

Here is my Angular service post method: getUserDetails(username , password) { alert(password); return this.http.post<myData>("http://localhost/test/api/auth.php", { username, password }); } This is the structure of my PHP file: <?php ...

Tracker.autorun subscription triggers repeated firing of publish callback

Working on a ReactJS and Meteor project, I encountered an unexpected behavior that I would like to discuss here: Within the code, there is a block with Tracker.autorun containing a call to Meteor.subscribe. On the server side, there is a corresponding Met ...

React: Modifying a single input field out of many

Can someone please review this code snippet: https://stackblitz.com/edit/react-koqfzp?file=src/Section.js Whenever I add an item, a random number is also added that I want to be able to edit. This number is displayed in a Material UI Text Field component. ...

Bring JavaScript Function into Vue's index.html File

Recently in my code files, I noticed the following: function example() { console.log("testing"); } In another file, I have something like this: <head> <script src="../src/example.js" type="text/babel"></sc ...

Add the scss file to the vuejs component npm package only if certain conditions specified in the project are met

Creating css/scss themes for my Vue Components Npm package has been a focus of mine lately. This particular package is local and currently being tested using npm link. Both the Package and Project are utilizing webpack. index.js of Package import "./src ...

Highlighting a Table Column with a Radio Button

I am struggling with controlling the highlight of a table using only radio buttons. When I try to change the selector to input:radio, it doesn't work as expected. It seems to only work with the selector provided in my code snippet. $("th").on("clic ...

Incorporating user names into socket.io chat for disconnect functionality

I've recently started using socket.io and have been developing a messaging chat feature. By adding usernames to the chat upon login and message submission, everything seemed to be working smoothly. However, I'm facing an issue with retrieving use ...

The X axis labels are missing on the Google column chart

Problem: All column charts are rendering correctly in Internet Explorer. However, Upon clicking the "View Build Performances" button, project names are displayed on the x-axis of the first three column charts only. The other column charts do not show pro ...

Can you include the dollar symbol in the currency format?

I currently have this code that formats numbers into currency format, however I would like to include the dollar sign ($) before the numbers. document.getElementById("numbers").onblur = function (){ this.value = parseFloat(this.value.r ...

Employing ng-repeat within a ui-scope

I'm having trouble getting my ui-view to update dynamically using ng-repeat. I'm not sure if what I want to do is even possible because when I add static objects to intro.html, they display properly. Thank you for any assistance, JS }).st ...

The Safari browser is currently having trouble loading the data sent back from the server

After successfully developing and deploying my website carspeedyrental.com, I received reports from some clients indicating that the website does not display available cars on the iPhone Safari browser. Interestingly, when tested on various browsers on A ...

Refreshing a section of a webpage using AJAX and PHP

After creating a RESTful API in PHP, I can easily register information by accessing the address . This registration process involves sending a POST request. Below is an overview of my method: File: api.php <?php /* File: api.php */ private function ...

Tips for managing nested arrays using a v-for loop

Imagine I have a dynamic dropdown menu that needs to be filled with items based on the selection made in the previous dropdown. For example, consider a scenario where vehicle data is structured like this in a file named vehicleDetails.json: { "1": { ...

When you click on the text, the calendar will pop up for you to

When the text "SetExpiryDate" is clicked, a date picker opens. After selecting a date, the text changes to "Expires ${date}" where the selected date is inserted. If no date is selected, the text remains as it is. I'm curious how I can implement this ...