I have this array of objects.
[
{
"id":181,
"user_id":"3",
"order_details":
[
{"id":164,
"order_id":"181",
"quantity":"1",
"price":"5.00"
},
{"id":163,
"order_id":"181",
"quantity":"6",
"price":"10.00"
}
]
}
]
These are order items in from cart.
I want to calculate the total for each order_detail using price * quantity.
I have this function in the computed property of the component.
total: function(){
for (var i=0; i< this.invoice.length; i++){
for(var j=0; j<this.invoice[i].order_details.length; j++){
return this.invoice[i].order_details[j].price * this.invoice[i].order_details[j].quantity;
}
}
}
This returns the same total for all the items in the order_details. What are my missing? Is this the right way to do this in vue?
UPDATE
I need to display the data this way:
<tr v-for="item in order.order_details">
<td>{{item.quantity}}</td>
<td>{{item.product.price}}</td>
<td>{{total}}</td>
</tr>
So I am expecting that for each order detail, the function should run and return price * quantity
Sample Output:
## Qty | Price | Total
## 2 | 5 | 10
## 3 | 5 | 15