M
M
med1um2020-06-04 21:03:42
Vue.js
med1um, 2020-06-04 21:03:42

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

2 answer(s)
M
med1um, 2020-06-05
@med1um

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)" ...>

A
Alex, 2020-06-04
@Kozack Vue.js

Do you have an array? So delete both from the array https://developer.mozilla.org/uk/docs/Web/JavaScri...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question