Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
Apollo pagination with vuex

I'm trying to get vuetify's pagination component to work with the nuxtjs@apollo module.

But I'm having a hard time getting it to work with my vuex store.

I'll skip over most of the code as its a lot of boilerplate.

First of all in order to populate my initial state I send a graphql query to my back end and commit these to my state.

const client = context.app.apolloProvider.defaultClient

const response = await client.query({
  query: productsGQL,
  variables: {
    first: 5,
    page: 1
  }
})

commit('setProducts', response.data.products.data)
commit('setPagination', response.data.products.paginatorInfo)
commit('setPage', response.data.products.paginatorInfo.currentPage)

this works fine, products, pagination and page are all set with initial data.

Now, I have 2 components a CardComponent that contains all of the products like so

<script>
export default {
  name: 'CardComponent',

  computed: {
    products() {
      return this.$store.getters.getProducts
    }
  }
}
</script>

And a PaginationComponent:

<template>
  <div>
    <v-pagination
      v-model='page'
      circle
      :length='total_pages'
    />
  </div>
</template>

<script>
export default {
  name: 'PaginationComponent',

  data() {
    return {
      total_pages: Math.ceil(this.$store.getters.getPagination.total / this.$store.getters.getPagination.perPage)
    }
  },

  computed: {
    page: {
      get() {
        return this.$store.getters.getPage
      },
      set(value) {
        return this.$store.commit('setPage', value)
      }
    }
  }
}
</script>

Page Initial value is 1, when I click on the second page the Page variable is updated to 2, this is also than reflected in my state.

The thing I'm unsure about is: how do I requery the database? the page is being updated but the products displayed are still the same, and I'm not sure how to go about this.

If you some more code from the store I'll show it here.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Using refresh() fixed the issue: https://apollo.vuejs.org/api/smart-query.html#refresh

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda