I'm wondering how to calculate a total on a vue.js list. My situation is a bit complex, so please allow me to use an example. Let's say that I'm rendering a table of invoice items. Here's my code:
<table>
<template v-for="(invoice_item, index) in invoice_items" v-if="invoice_item.category === 'widgets'">
<tr>
<td>@{{ invoice_item.name }}</td>
<td><input type="number" class="inline-edit" v-model="invoice_item.rate"></td>
<td><input type="number" class="inline-edit" v-model="invoice_item.quantity"></td>
<td><input type="number" class="inline-edit" v-model="invoice_item.activation_fee"></td>
<td class="subtotal">@{{ computeSubTotal(invoice_item) }}</td>
</tr>
</template>
</table>
For each row, I've computed a subtotal and displayed it in the last column. Here's that code in my vue.js javascript:
computeSubTotal: function(invoice_item) {
return(this.formatPrice((parseFloat(invoice_item.rate) * parseFloat(invoice_item.quantity) + parseFloat(invoice_item.activation_fee))));
},
This works great. However, now I want to display the total of all of the subtotals. In other words:
How would I pull this off?
Thanks!