08.02.2017 Views

vuejs

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Working with real data 105<br />

1 <br />

2 <br />

3 <br />

4 Upvote<br />

5 <br />

6 <br />

7 <br />

1 Vue.component('story',{<br />

2 template: '#template-story-raw',<br />

3 props: ['story'],<br />

4 methods: {<br />

5 upvoteStory: function(story){<br />

6 story.upvotes++;<br />

7 $.ajax({<br />

8 url: '/api/stories/'+story.id,<br />

9 type: 'PATCH',<br />

10 data: story,<br />

11 });<br />

12 }<br />

13 },<br />

14 })<br />

We brought back the upvote method and placed it inside our story component. Making a PATCH<br />

request now, providing the new data, the server updates the upvotes count.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!