0

In my Vue template, I'm currently setting response data to an object called dateEvents which is structured like this:

<tbody  v-for="dateEvent in dateEvents">
  <tr> 
    <td>{{ dateEvent.id }}</td>
    <td>{{ dateEvent.status }}</td>
    <td><button v-on:click="changeStatus" type="button" class=" taskButton btn-default"><a style="color:white;">Accept</a></button></td>
  </tr>
</tbody>

My data shows properly, and I'm calling a method/function with button click, and I can get the click to fire an event but not getting the value properly. I want to have access to the id and status of the clicked row's button within the method but can't figure out how to get it. dateEvent is being set in another function in my vue code so using this.dateEvents gets the base object but I need the specific data sent from the row that is clicked. Here's the vue code:

//vue code
methods: {
  changeStatus: function(event) {
    alert(this.dateEvents.status)
  },

1 Answer 1

3

You can pass arguments to the method. In the template:

<button @click="changeStatus(dateEvent)">

And in your method:

changeStatus: function(dateEvent) {
  console.log(dateEvent.status, dateEvent.id);
},
Sign up to request clarification or add additional context in comments.

2 Comments

So simple, I don't know why I didn't just pass it to the method to begin with. Thanks! Trying this now
Don't worry - it's a pretty common stumbling block when getting used to Vue's template system.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.