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

127
Visualizações
watch changes of nested data in vuejs

I want to watch changes of families variable which contains nested objects

 <component-test
    v-for="family of familiesToDisplay"
    // rest
   />

data: () => ({
    families: [],
  }),

      computed: {
        familiesToDisplay() {
          return this.families.fillter(family => family.members > 4);
        },
    
      },

In some response I have seen some recomanding the use of watch but in my case I didn't knew how to implement it since I have never used before. so the request is to get changes of nested objects in families (as objects I have person and work so if a name of a person has been changed or its work has been changed changes must be retreived here)

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

0

This code should work fine, however, it is necessary to correctly mutate objects inside an array. You need to use this.$set or replace the object with a new one to trigger vue re-rendering a list and recalculation of a list. For example, you can change them like this, (full working example you can find here):

export default {
  name: "HelloWorld",
  components: {
    Display,
  },

  data: () => ({
    families: [
      { name: "foo-1", members: 1 },
      { name: "foo-5", members: 5 },
      { name: "bar-6", members: 6 },
      { name: "bar-3", members: 3 },
    ],
  }),

  methods: {
    onClick() {
      this.families.forEach((family) => {
        this.$set(family, "members", this.getRandomNumber());
      });
    },

    getRandomNumber() {
      return Math.floor(Math.random() * 10) + 1;
    },
  },
};
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