javascript - How to get id from a loop's item in vue.js? -
i have loop this:
<div class="jokes" v-for="joke in jokes"> <strong>{{joke.body}}</strong> <small>{{joke.upvotes}}</small> <button v-on:click="upvote"><i class="fa fa-arrow-down"></i></button> <div> i need joke.id can post backend , increment votes.
the method should this:
methods: { upvote: function(e) { axios.post( this.base_url + "/api/joke/" + this.joke.id + "/upvote", { token: 'secret', }).then(function(data){ console.log(data); }); } }, how can achieve this?
pass joke in click.
<button v-on:click="upvote(joke)"><i class="fa fa-arrow-down"></i></button> use in method.
upvote: function(joke) { axios.post( this.base_url + "/api/joke/" + joke.id + "/upvote", { token: 'secret', }).then(function(data){ console.log(data); }); }
Comments
Post a Comment