Answer the question
In order to leave comments, you need to log in
How to implement the removal of completed tasks?
How to implement the removal of completed tasks?
jsfiddle code
Answer the question
In order to leave comments, you need to log in
Before implementing the deletion, we will give the user the opportunity to mark the task as completed. Let's add support for the v-model directive to the task component. We change the name of the parameter from task to value (or set the model if we need to set some other name), and wrap the task object itself in a Proxy that will intercept the setting of property values, collect a new object and send it to the parent component:
computed: {
task() {
return new Proxy(this.value, {
set: (target, prop, value) => {
this.$emit('input', { ...target, [prop]: value });
return true;
},
});
},
},
v-model
corresponding input fields in the same way):
Now the deletion itself. In the task component, add a button, by clicking on which we emit an event:<input type="checkbox" v-model="task.done">
<button v-if="task.done" @click="$emit('delete')">delete</button>
<task-element
v-for="(n, i) in todos"
v-model="todos[i]"
@delete="todos.splice(i, 1)"
></task-element>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question