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.

Display Prev/Next blog page buttons using URL query (pagination)

See original GitHub issue

I’ve been searching the Nuxt JS Content docs to try and find some kind of example where I can list out all of my blog posts on a page and have some kind of blog pagination.

I did manage to find an article, but it suggested using the following URL structure:

And the parent /blog page would redirect to the /page/1`.

I actually want to utilise the URL query and hopefully have something simplier.

I’m currently getting all of my blog posts on my page:

<script>
export default {
  head () {
    return {
      title: 'Domain Monitor | Blog',
      meta: [
        { hid: 'og:title', name: 'og:title', content: 'Domain Monitor | Blog' },
        { hid: 'description', name: 'description', content: 'Domain Monitor updates, product news, useful guides and information to help you start monitoring your next domain. Starting reading today.' },
        { hid: 'og:description', name: 'og:description', content: 'Domain Monitor updates, product news, useful guides and information to help you start monitoring your next domain. Starting reading today.' }
      ]
    }
  },
  async asyncData ({ $content }) {
    const blogs = await $content('blog')
                        .sortBy('createdAt', 'desc')
                        .fetch()
    return {
      blogs
    }
  }
}
</script>

I’m displaying my blogs via a v-for="(blog, index) in blogs".

I was thinking of using a Javascript .slice() method to slice the array, and then when I click a Next button it changes the URL to:

But I got stuck trying to find a proper implementation of this, and wondered how this would scale with hundreds of posts…

Any suggestions?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
NozomuIkutacommented, Dec 25, 2020

@sts-ryan-holton

mounted is called after asyncData is completed. You have to move the whole logic to fetch blogs to mounted hook, so that you can use this.$route.query.page there.

By the way, to be honest, you should review Nuxt’s basics such as its lifecycle. Nuxt community well organizes information for us to achieve our goals in most cases. 🙌

0reactions
sts-ryan-holtoncommented, Jan 6, 2021

Any update here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination with rel="next" and rel="prev"
Implementing rel="next" and rel="prev" · The first page only contains rel="next" and no rel="prev" markup. · Pages two to the second-to-last page should...
Read more >
Next and Before Links for a django paginated query
The problem lies in the Previous and Next buttons. The links for the return query goes to /records/search/?query=a (search sample is a )...
Read more >
Pagination attributes: link rel="next" and rel="prev"
When should I use the pagination attributes? ... pagination is for instance used to split up product pages and blog category pages.
Read more >
Consider changing pagination to just "Previous" and "Next ...
Having a simple "Previous" and "Next" button of sorts would at least solve the performance problem. Displaying these buttons can be done ...
Read more >
Example of pagination with jQuery and ColdFusion with " ...
Also note I'm doing "sloppy" paging with cfoutput startrow and maxrows. ... Show Prev if start gt 1 ---> <cfif url.start gt 1>...
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