vuejs
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Integrating vue-resource 114<br />
1 <br />
2 <br />
3 <br />
4 Update Story<br />
5 <br />
6 <br />
7 Cancel<br />
8 <br />
9 <br />
1 Vue.component('story',{<br />
2 ...<br />
3 methods: {<br />
4 ...<br />
5 updateStory: function(story){<br />
6 this.$http.patch('/api/stories/'+story.id , story)<br />
7 //Set editing to false to show actions again and hide the inputs<br />
8 story.editing = false;<br />
9 },<br />
10 }<br />
11 ...<br />
12 })<br />
Updating story actions<br />
Here it is up and running. After the PATCH request is finished successfully, we have to set<br />
story.editing to false in order to hide the inputs and bring back the action buttons.<br />
10.3.2 Create New Stories<br />
Now for a bit trickier task, we are going to give the user the ability to create a new story and save it to<br />
our server. First, we must provide inputs so the new story can be typed in. To make this happen, we<br />
will create an empty story and we’ll add it to the stories array using the push() javascript method.<br />
We will initialize all the story’s attributes to null, except from editing. We want to immediately<br />
manipulate the story, so the editing will be set to true.