I'm practicing with a simple to-do list with vue.js. I'm trying to sum all price within an array. To do that I wrote a little function inside computed,
but something has gone wrong, here is my js:
var app= new Vue({
el: "#app",
data: {
message: "Lista della spesa",
seen: true,
todos: [
{msg: 'prezzemolo', price: 10},
{msg: 'pomodori', price: 20},
{msg: 'zucchine', price: 5}
],
},
methods: {
addToDo: function() {
if(this.nome && this.prezzo) {
this.todos.push({msg: this.nome, price: this.prezzo});
}
this.nome = "";
this.prezzo = "";
},
RemoveThis: function(index) {
this.todos.splice(index,1);
}
},
computed: {
totale: function() {
var total = 0;
this.todos.forEach(function() {
total += this.todos.price
});
return total;
}
}
});
There is something inside the forEach that is breaking the function, anyone know why?