I have a list that I created like this:
<tbody>
<tr v-for="(post, index) in posts" v-bind:index="index">
<td>{{ post.rut }}</td>
<td>{{ post.names }} {{ post.father_lastname }} {{ post.mother_lastname }}</td>
<td>
<input type="text" @blur="handleBlur(post.amount)" class="form-control" id="exampleInputEmail1" v-model="post.amount" placeholder="Ingresa el monto">
</td>
</tr>
</tbody>
I have a method like this one in Vuejs:
handleBlur(value) {
this.total_inputs = parseInt(this.total_inputs) + parseInt(value);
},
The thing is that if I edit any input it adds correctly I mean:
If it was 0.. and I add a value 3 in the input it will say 3+0 = 3 etc...
The thing is that I just do not need to add because If I edit same input that it has 3 and I change to 4 it should say total = 4 but it says 3+4 = 7 and it's wrong because the 4 replaced the 3 number so I wonder how can I fix my code to do that?
Thanks
this.total_inputs = this.posts.reduce((i, post) => i + post.amount, 0);