question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pagination with Axios

See original GitHub issue

Win 10 (1803) | Chrome 69 | Bootstrap vue 2.0.0-rc.11

When using pagination with axios response to calculate total number of pages, i have to double click the pager in order to see the next page contents:

<b-pagination
  v-if="numbers.total > 24"
  size="md"
  v-model="currentPage"
  :limit="6"
  :total-rows="numbers.total"
  :per-page="24"
  @click.native="fetchNumbers()"
></b-pagination>

numbers total are comes from:

    fetchNumbers () {
      return axios.get(globalConfig.NUMBERS_URL, {
        params: {
          limit: 24,
          offset: (this.currentPage - 1) * 24
        }
      })
        .then((resp) => {
          this.numbers = resp.data
          // console.log(resp)
        })
        .catch((err) => {
          console.log(err)
        })
    },

With lodash debounce, if i set a small delay, it works as intended, i suspect async there.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
eamon-hgukcommented, Dec 21, 2018

I had a similar issue and fixed it by picking up the page via the method call from the change event, for example: <b-pagination size="md" :total-rows="rowsCount" v-model="selectedPage" :limit="5" :per-page="50" @change="pageChanged"> </b-pagination>

Then the model value is passed to the pageChanged method, and can be picked up like so:

pageChanged(page) { // Do things with the page value }

The reason the other way doesn’t always work, is that getting the model via the normal way, doesn’t seem to update in time after the change (or click) event to have the new value.

1reaction
jptrosclaircommented, Sep 24, 2018

Use @change instead of @click to fire off fetchNumbers() from user interaction after the model is updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update axios request for pagination - Stack Overflow
I have an axios GET request that displays an array of data, but only displays 15 items at a time. The API url...
Read more >
Vue Pagination with Axios and API (Server Side ... - BezKoder
In this tutorial, I will show you how to make Pagination in a Vue.js Application with existing API (Server Side pagination) using Axios...
Read more >
axios-hooks pagination - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
Retrieving Paginated API Data With Axios - xkln.net
I recently encountered an API which would only permit a limited number of objects to be returned. The objects in this case were...
Read more >
ReactJS Pagination - React axios.get - YouTube
ReactJS Pagination - React axios.getSource Code : https://tutorial101.blogspot.com/2021/10/reactjs- pagination -react-axiosget.html.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found