0

I'm looping through a list of songs coming from a database with a button that deletes the song targetted

<div v-for="(song, index) of songs" :key="index">
  ...
  ...
  <button @click="deleteSong(song._id)">Delete</button>
</div>

then in the method

deleteSong(id) {
  axios.delete("/api/songs/" + id)
}

What I also want is to get the target event object in order to instantly delete the row without having to refresh the page

I tried @click="deleteSong(e, song._id)" and some other things but I always getundefined, any idea how to do that?

2 Answers 2

1

to get to the underlying event you can use $event

see https://v3.vuejs.org/guide/events.html#methods-in-inline-handlers

Sign up to request clarification or add additional context in comments.

Comments

0

As the docs show, $event can be used to refer to the associated event:

<button @click="deleteSong(song._id, $event)">Delete</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.