Answer the question
In order to leave comments, you need to log in
How to remove an item from a ToDo list?
There is an example of a todo list: https://codesandbox.io/s/github/vuejs/vuejs.org/tr...
Question: how to add the ability to splice () to delete an element that was clicked with the middle @click button. middle?
If possible, then with an explanation of the logic - where exactly to add the handler and how the data is transmitted.
Answer the question
In order to leave comments, you need to log in
Figured it out myself!
From the child component, you need to send an event to the parent component, while the event itself can be called anything, for example, "delete-item": And on the parent component, you need to attach a handler function to this event (call it, for example ,
deleteItem()): pass the index (from for) of the element to be removed, or you can use another way - call the code in place like this:
<div @click.right="$emit('delete-item')" ...>
<tree-item @delete-item="deleteItem(index)" ...>
<tree-item @delete-item="item.children.splice(index, 1)" ...>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question