Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda