Now let us proceed to another piece of functionality our stories
list should have: Deleting a story we don't like. To remove a story from the array and the DOM, we are going to use Vue's $remove()
method, which searches for an item and removes it from target array.
Note
The $remove()
method works as follows. When you want to remove an item from an array called items
you can do:
vm.items.$remove(item)
<td> <div class="btn-group"> <button @click="upvoteStory(story)" class="btn btn-primary"> Upvote </button> <button @click="deleteStory(story)" class="btn btn-danger"> Delete </button> </div> </td>
We append a Delete
button to the actions
column, bound to a method to delete the story. The deleteStory
method will be:
Vue.component('story',{ ... methods: { ... deleteStory: function...