O'Reilly logo

The Majesty of Vue.js by Kostas Maniatis, Alex Kyriakidis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Updating data

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',{ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required