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

188
Visualizações
Vue Js: empty string when posting to API

in my below code .. i'm updating data using Node Js REST API and in remaining field i have set an equation using v-model=remaininginst to keep track of the result and save it into remaininginst so i can post it to API, but on console.log i'm getting NaN empty data stored in remaininginst and it's not posting due to this error..

am i doing something wrong here? and if yes is there a way to do it?

 <h4 v-model="remaininginst"> remain : ${{ Number(instPrice) -(Number(totPaid) + Number(instOne) )  }}</h4> //equation shows coorect data on html
                                        
 
</template>

export default {
    name: 'light-table',
    components: {
loader
    },
    data() {
        return {
   
            instPrice: "",
            remaininginst:  "",
            instOne:""
            

        };
    },
    computed: {

        totPaid() {
            let installments = this.Flats.payment.installment_payment.installments;
            let paidInstallments = installments.filter(obj => obj.is_paid == true);
            let totalPaid = paidInstallments.reduce((sum, obj) => sum + parseInt(obj.amount), 0);
            return totalPaid;
        }

    },
    methods: {
      

        PostPayment() {
            this.error = []
            console.log(this.payment);

            var data = {
                payment: {
                    installment_payment: {
                  

                  remaining: this.remaininginst,//getting Nan

                    },
                    paid_amount: this.instOne,
                },
            }
           

            BuildingsService.Payment(this.FlatId, data).then((response) => {
                console.log(data);
              
            });
        

        },

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

0

You could not use v-model on h4 tag.You could try to create another computed property which contains the expression you need and show it on view.Below sample move remaininginst from data to computed as a computed property.

 <template>
  <h4>
    remain : $ {{ remaininginst }}
  </h4>
</template>
<script>
export default {
  data() {
    return {
      instPrice: "",
      instOne: "",
    };
  },
  computed: {
    totPaid() {
            let installments = this.Flats.payment.installment_payment.installments;
            let paidInstallments = installments.filter(obj => obj.is_paid == true);
            let totalPaid = paidInstallments.reduce((sum, obj) => sum + parseInt(obj.amount), 0);
            return totalPaid;
        }

    remaininginst() {
      return (
        Number(this.instPrice) - (Number(this.totPaid) + Number(this.instOne))
      );//return any string you want
    },
  },
  methods: {
    PostPayment() {
      console.log(this.remaininginst);
    },
  },
};
</script>

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