[Vuejs]-VueJS sum pivot table

2👍

You could create a method to sum up the quantities using Array#reduce:

methods: {
    sumOfQuantities: function(book) {
       return book.places.reduce(function(sum, next) {
           return sum + Number(next.pivot.quantity);
       }, 0);
    }
}

Note: Since your quantity is a string, you need to convert it to a Number (e.g. using Number()).

You can then access it in your template using v-text for example:

<div v-for="book in books">
    <div v-text="sumOfQuantities(book)"></div>
</div>
👤nils

Leave a comment