0
I’m creating a TodoList
where I have the editTodo()
which will allow you to change an item in the list, but in the vi declaration which is passed as a parameter the reference todo
which I use in the v-for
and I got the doubt, why not use the array
todos
as a parameter and how the method can display this nickname or reference?
Part of the component:
<div v-for="(todo,index) in todos" :key="todo.id" class="todo-item">
<div class="todo-item-left">
<div v-if="!todo.editing" class="todo-item-label"
@dblclick="editTodo(todo)">{{todo.title}}
</div>
<input v-else class="todo-item-edit" type="text" v-model="todo.title">
Method:
editTodo(todo){
todo.editing=true
}
I did not understand what advantage would have to pass the whole list if you want to edit a specific item.
– bfavaretto
And your second question is about the implementation details of Vue? I don’t know how they implemented it, but in practice each iteration has an independent scope. As if you did
for (let i=0;, i<10; i++)
and walk thisi
for a function in the body of the loop.– bfavaretto