Answer the question
In order to leave comments, you need to log in
Getting to know Vue. Is this method for working with data done correctly?
Getting to know Vue.
I am writing the toggleTask method for ToDo (i.e. marks done / not done).
Is this solution correct? Are there any Vue-way ways to improve it?
methods:{
toggleTask(id){
let taskIndex;
this.tasks.forEach( (item, index) => {
if ( item.id === id){
taskIndex = index
}
});
this.tasks[taskIndex].completed = !this.tasks[taskIndex].completed;
}
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question