Instead of directly altering your data, you can utilize a computed property to generate a new version of your list with the necessary items included. This approach is generally considered to be less prone to errors and easier to comprehend. Check out this functional example:
<template>
<div>
<ul>
<li v-for="(item, index) in itemsWithTotals" :key="index">
<span>{{ item.total1 }} - {{ item.total2 }}</span>
</li>
</ul>
</div>
</template>
const ITEMS = [
{ name: 'item1', price: 20, amount: 10, discount: 0 },
{ name: 'item2', price: 50, amount: 15, discount: 0.25 },
{ name: 'item3', price: 35, amount: 20, discount: 0.75 },
];
export default {
data() {
return { items: ITEMS };
},
computed: {
itemsWithTotals() {
return this.items.map(item => {
const total1 = item.price * item.amount;
const total2 = total1 * (1 - item.discount);
return { ...item, total1, total2 };
});
},
},
};
Note that I have updated your original data to have numerical properties instead of strings.