I am putting together a simple price quote page using Vue, I am trying to sum two items in the same row. I tried using the computed property but I am struggling with the format. How should I format this to show to sum of disbursement and price for each row as per my example?
new Vue({
el: '#search',
data: {
items: [
{ province: "Alberta", disbursement: 1, price: 300 },
{ province: "British Columbia", disbursement: 1, price: 75 },
{ province: "Manitoba", disbursement: 1, price: 10 },
{ province: "New Brunswick", disbursement: 1, price: 10 },
{ province: "Newfoundland & Labrador", disbursement: 1, price: 10 },
{ province: "Nova Scotia", disbursement: 1, price: 10 },
{ province: "Northwest Territories", disbursement: 1, price: 10 },
{ province: "Nunavut", disbursement: 1, price: 10 },
{ province: "Ontario", disbursement: 1, price: 10 },
{ province: "Prince Edward Island", disbursement: 1, price: 10 },
{ province: "Quebec", disbursement: 1, price: 10 },
{ province: "Saskatchewan", disbursement: 1, price: 10 },
{ province: "Yukon", disbursement: 1, price: 10 },
]
},
computed: {
total: function() {
return parseInt(this.items.disbursement) +
parseInt(this.items.price);
}
}
});
My HTML is formatted like this
<tr v-for="item in items">
<th scope="row"><input type="text" v-model="item.province"/></th>
<td>$<input type="number" v-model="item.price"/></td>
<td>$<input type="number" v-model="item.disbursement"/></td>
<td>${{total}}</td>
</tr>
I am trying to add items.disbursement + items.price in the total