Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Created December 21, 2017 14:18
Show Gist options
  • Save christiannwamba/237680a1fce1aa940aaccd59cc9c123b to your computer and use it in GitHub Desktop.
Save christiannwamba/237680a1fce1aa940aaccd59cc9c123b to your computer and use it in GitHub Desktop.
var articleComment = {
template: `
<div>
<h3>Comments</h3>
<div class="form-group">
<input type="text" class="form-control" placeholder="Name" v-model="name" />
</div>
<div class="form-group">
<textarea class="form-control" placeholder="Comment here..." v-model="content"></textarea>
</div>
<button class="btn btn-info" @click="onSubmit()">Submit</button>
<h4 v-if="comments.length > 0">Existing comments</h4>
<div class="list-group">
<a class="list-group-item" v-for="comment in comments">
<h4 class="list-group-item-heading">{{comment.name}}</h4>
<p class="list-group-item-text">{{comment.content}}</p>
</a>
</div>
</div>
`,
data() {
return {
comments: [],
name: '',
content: ''
}
},
methods: {
onSubmit: function() {
this.comments.push(
{name: this.name, content: this.content}
)
this.name = '';
this.content = '';
}
}
}
var app = new Vue({
el: '#app',
components: {
'article-comment': articleComment
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment