vuejs
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Integrating vue-resource 125<br />
1 Vue.component('story', {<br />
2 template: '#template-story-raw',<br />
3 props: ['story'],<br />
4 methods: {<br />
5 deleteStory: function (story) {<br />
6 this.$parent.stories.$remove(story)<br />
7 this.$http.delete('/api/stories/' + story.id)<br />
8 },<br />
9 upvoteStory: function (story) {<br />
10 story.upvotes++;<br />
11 this.$http.patch('/api/stories/' + story.id, story)<br />
12 },<br />
13 editStory: function (story) {<br />
14 story.editing = true;<br />
15 },<br />
16 updateStory: function (story) {<br />
17 this.$http.patch('/api/stories/' + story.id, story)<br />
18 // Set editing to false to show actions again and hide the inputs<br />
19 story.editing = false;<br />
20 },<br />
21 storeStory: function (story) {<br />
22 this.$http.post('/api/stories/', story)<br />
23 .then(function (response) {<br />
24 // After the the new story is stored in the database<br />
25 // we fetch again all stories<br />
26 // vm.fetchStories();<br />
27 // OR Better, update the id of the created story<br />
28 Vue.set(story, 'id', response.data.id);<br />
29 // Set editing to false to show actions again and hide the inputs<br />
30 story.editing = false;<br />
31 });<br />
32 },<br />
33 }<br />
34 })<br />
35 new Vue({<br />
36 el: '#v-app',<br />
37 data: {<br />
38 stories: [],<br />
39 },<br />
40 ready: function () {<br />
41 this.fetchStories()<br />
42 },