[Vuejs]-How to sum values inside v-for statement (vuejs)

2👍

You should not try to compute the sum with v-for. V-for is meant for presentation.

Instead add a computed value that calculates the subtotal. Inside the computed you should loop through the array, calculate the sum and return it. The computed property also calculates the new value automatically if any of the inputs change.

0👍

You may sum the values of your array with the reduce function. The total will update automatically if any score changes.

<td><span class="subtotal">{{ configs.reduce((a, c) => a + parseInt(c.score), 0) }}</span></td>
👤Rodris

Leave a comment