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

137
Visualizações
V-Model Not Updating Data Function

I'm putting together a child component that will pass data back up to its parent each time one of the increment buttons are clicked. But v-model is not updating the data function. Even though the value of the number input field is changing the value of kf_units_leaking stays the same.

<template>
   <div>
        <input
          @click="
            decrementValue($event)
            sendChildData(kfData)
          "
          type="button"
          value="-"
          class="btn button-minus border icon-shape icon-sm lh-0 bg-dark text-light"
          data-field="quantity"
        />
        <input
          id="kfUnitsLeaking"
          type="number"
          step="1"
          v-model="kfData.kf_units_leaking"
          name="quantity"
          class="form-control quantity-field border-0 text-center w-25"
        />
        <input
          @click="
            incrementValue($event)
            sendChildData(kfData)
          "
          type="button"
          value="+"
          class="btn button-plus border icon-shape icon-sm lh-0 bg-dark text-light"
          data-field="quantity"
        />
   </div>
</template>

<script>
export default {
  name: 'audittedKitchenFaucets',
  props: {
    sendChildData: {
      type: Function,
    },
    incrementValue: {
      type: Function,
    },
    decrementValue: {
      type: Function,
    },
  },
  data() {
    return {
      kfData: {
        kf_units_leaking: 0,
      },
    }
  },
}
</script>
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

This is a problem with reactivity in vue.js. you need to use $set for updating objects based on key and array based on it's index. You can find more info here : https://v2.vuejs.org/v2/api/#vm-set

EDIT

This problem in reactivity is fixed in Vue version 3 and you can directly pass object key to v-model like this working example: https://playcode.io/943725/

about 4 years ago · Santiago Trujillo Relatório

0

First of all, this code will not work and will cause a syntax error.

  @click="
    decrementValue($event)
    sendChildData(kfData)
  "

You need to separate the functions with a semicolon ;

   @click="
    decrementValue($event);
    sendChildData(kfData)
  "
about 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