We used to have a function that allowed the user to vote any story he wanted to. But now we want something more. We want the server to be informed every time a story is voted, ensuring that story votes are updated in the database as well.
To update an existing story we have to make an HTTP PATCH
or PUT
request to api/stories/{storyID}
.
Inside the upvoteStory
function, which is to be created, we are going to make a HTTP call, after we have increased story upvotes
. We will pass the newly updated story
variable in the Request Payload, in order to update the data in our server:
<td> <div class="btn-group"> <button @click="upvoteStory(story)" class="btn btn-primary"> Upvote </button> </div> </td> Vue.component('story',{ template: '#template-story-raw', props: ['story'], methods: { upvoteStory: function(story){ story.upvotes...