Skip to content

Instantly share code, notes, and snippets.

@nOy39
Last active July 2, 2018 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nOy39/9677ff989367119a5974f7eb27cddfa7 to your computer and use it in GitHub Desktop.
Save nOy39/9677ff989367119a5974f7eb27cddfa7 to your computer and use it in GitHub Desktop.
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