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

212
Visualizações
Vue Array shuffling 2 time(in ssr and browser)

I want to shuffle an array and pass it to the component. It's working when going direct to the page with nuxt-link.

<template>
  <div>
  
    <CardsMetalCard :myCategory="myCategory" :catMetal="catMetal" />
  </div>
</template>
computed: {
...mapGetters("design", {
  designCategory: ["category"],
}),

myCategory() {
  var result = this.designCategory.find((i) => i.url === this.category);
  this.catMetal = result.metal;
  var newRelatedArray = this.designCategory.filter(
    (i) =>
      i.metal === result.metal 
  );
  // Shuffle is method to sort array and I console.log(array) before return in shuffle
  return this.shuffle(newRelatedArray);
},

},

Everything works fine in nuxt-link. But when I refresh the page. Array gets shuffled 2 times. 1 in SSR and the other in the browser. So my component loads data from SSR shuffle and then the component renders again with browser shuffle. In this scenario, the Final component has a mismatched value from different objects.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Weird behavior with the variable data

With help from This question's answer. I tried getting data in async Fetch() method so it can work on Both SSR and browser.

async fetch() {
    var designCategory = await this.$store.getters["design/category"];
    var result = designCategory.find((i) => i.url === this.category);
    this.catMetal = result.metal;
    var newRelatedArray = designCategory.filter(
      (i) => i.metal === result.metal 
    );

    this.myCategory = this.shuffle(newRelatedArray);
  },

And it worked.

about 4 years ago · Juan Pablo Isaza 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