R
R
razer962018-08-23 14:51:43
Vue.js
razer96, 2018-08-23 14:51:43

How to make pagination in nuxt.js given ssr?

Hello! For the first time I encountered the development of an online store on Nuxt.js. I would like to know how to quickly and correctly make pagination?
For the first time I encountered the development of a SPA for an online store. And ran into the issue of pagination. How to do pagination? Perhaps there are ready-made ssr plugins?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2018-08-23
@razer96

If everyone understands correctly, then

async asyncData(ctx) {
            let products = await ctx.app.$api.products(ctx.params.slug, ctx.query);
            return {
                products: products.data,
                total: products.total,
                perPage: products.per_page,
            }

watch: {
            '$route'() {
                this.getProducts();
            },
        },

getProducts() {
                this.$api.products(this.$route.params.slug, this.$route.query).then(products => {
                    this.products = products.data;
                    this.total = products.total;
                    this.perPage = products.per_page;
                });
            },

And when clicking on pagination:
this.$router.push({
   query: {
      ...this.$route.query,
      page: page,
   },
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question