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.

Integrating vue-resource 117<br />

We observe a small mistake in this block of code. When we are in “editing” mode (v-else block) the<br />

buttons for update and store are being shown together, but we only need one for each story since<br />

each story will be Stored or Updated, it can’t do both. So, if the story is an old one and the user is<br />

about to edit it, we need the update button. Else, if the story is new, we need the store button.<br />

A small mistake<br />

To bypass this issue, we are going to restructure our buttons. The Update button will only be<br />

displayed when the story is old. Accordingly the Save new button will be displayed when the story<br />

is a new one.<br />

You may have noticed that all stories fetched from the server have an id attribute. We are going to<br />

use this observation to define if a story is new or not.<br />

1 <br />

2 <br />

4 <br />

5 Update Story<br />

6 <br />

7 <br />

8 <br />

9 Save New Story<br />

10

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

Saved successfully!

Ooh no, something went wrong!