[Vuejs]-Vue Js: empty string when posting to API

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>

Leave a comment