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

107
Vistas
Redraw vue component on fetch update

When on button click I want to refresh list of items. Button is trigger on a sibling component. Watch method only gets called once. But I need a constant refresh

Parent element.

<template>
  <div class="container">
    <Filter @changedKeywords="reloadItems"></Filter>
    <List :platforms="platforms" :filters="keywords"></List>
  </div>
</template>

<script>
imports...

export default {
  name: "Holder",
  components: {Filter, List},
  methods: {
    reloadItems: function (data){
      if(data.keywords) {this.keywords = data.keywords};
    }
  },
  data(){
    return {
      keywords : null,
    }
  }
}
</script>

I want to redraw child this element multiple times, on each (filter)button click

<template>
  <section class="list">
    <div class="container">
      <div class="holder">
        <Game v-for="data in list" :key="data.id" :data="data" />
      </div>
    </div>
  </section>
</template>

<script>
import Game from "./Game";
export default {
  name: "List",
  props: ['filters', 'platforms'],
  components: {Game},
  data() {
    return{
      list: [],
    }
  },
  watch: {
    filters: async function() {
      console.log('gets called only once!!!'); // this is where I want to fetch new items
      const res = await fetch('/api/game/list/9', {
        method: 'POST',
        body: JSON.stringify({'filters' : this.filters})
      });
      this.list = await res.json();
    }
  },

}
</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When you're watching objects and arrays you need to use a deep watcher.

The Solution

watch: {
  filter: {
    deep: true,
    async handler(next, previous) {
      //your code here
    }
  }
}

The Reason

Javascript primitives are stored by value, but Objects (including Arrays which are a special kind of Object) are stored by reference. Changing the contents of an Object doesn't change the reference, and the reference is what is being watched. Going from null to some object reference is an observable change, but subsequent changes aren't. When you use a deep watcher it will detect nested changes.

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