Last active
July 2, 2018 13:21
-
-
Save nOy39/9677ff989367119a5974f7eb27cddfa7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bearsApi = Vue.resource('/blog/bears/'); | |
Vue.component('input-form', { | |
props: ['bears'], | |
data: function() { | |
return { | |
title: '', | |
id:'' | |
} | |
}, | |
template: | |
`<div> | |
<hr> | |
<input type="text" placeholder="Blog name" v-model="title"/> | |
<input type="button" value="Save" @click="save"/> | |
</div> `, | |
methods:{ | |
save() { | |
var bear = { | |
title: this.title, | |
}; | |
bearsApi.save({}, bear).then(result=> | |
result.json().then(data => { | |
this.bears.push(data); | |
})) | |
} | |
} | |
}); | |
Vue.component('bear-list', { | |
props: ['bears'], | |
template: | |
`<div> | |
<input-form></input-form> | |
<ul> | |
<li v-for="bear in bears"> | |
<span v-bind:title="bear.body">{{ bear.title}} </span> | |
</li> | |
</ul> | |
</div>`, | |
created: function () { | |
bearsApi.get().then(result => | |
result.json().then(data => | |
data.forEach(bear => this.bears.push(bear)) | |
) | |
) | |
} | |
} | |
); | |
new Vue({ | |
el:"#app", | |
template: '<bear-list :bears="bears" />', | |
data: { | |
bears: [ | |
] | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment