Having just started with Vue.js, I've managed to solve most of the issues I've encountered so far, but there's one that's stumping me.
I'm working on displaying a list of posts fetched from an API and I want to include a comments box for each post. Posting comments to the API is functioning correctly and adds them without any issues. However, I'm facing a problem where any text entered in one input field is being duplicated in all the other input fields due to the v-model binding.
<div class="row" v-if="">
<div class="col-md-11">
<input type="text" class="form-control" value="" title=""
placeholder="Add comments here.." v-model="note.note">
</div>
<div class="col-md-1">
<button type="button" class="btn btn-default" style="margin-left: -1.5rem" v-on:click="addNote(task.id)">Add Comment</button>
</div>
</div>
JS:
addNote: function (id) {
if (this.note.note) {
Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('value');
this.$http.post('api/note/create/' + id, this.note).then(function (response) {
this.fetchTaskList();
});
}
}
Screenshot:
https://i.sstatic.net/ispmR.png
Is there a different directive that would be more appropriate for this situation? Or is there another workaround?