[Vuejs]-VueJS computed properties data binding issue

3👍

The issue here is you are not using any key attribute in the loop. The key special attribute is primarily used as a hint for Vue’s virtual DOM algorithm to identify VNodes when diffing the new list of nodes against the old list.

Without keys, Vue uses an algorithm that minimizes element movement and tries to patch/reuse elements of the same type in-place as much as possible. Thus you are getting the below behaviour:

if I click on the checkbox of an incomplete task in Incomplete List, or a complete task in Completed List, the task below it gets toggled too.

So, to resolve this you simply need to bind key to each loop like:

<li v-for="task in incompleteTasks" :key="task.id">
   <input type="checkbox" v-model=task.completed>{{ task.description }}
</li> 

With keys, it will reorder elements based on the order change of keys, and elements with keys that are no longer present will always be removed/destroyed.

Working Fiddle

Leave a comment