Skip to content

Instantly share code, notes, and snippets.

@InTheCloudDan
Created June 19, 2017 22:20
Show Gist options
  • Save InTheCloudDan/623b4637a3ca8313dd5894e8ac5245cd to your computer and use it in GitHub Desktop.
Save InTheCloudDan/623b4637a3ca8313dd5894e8ac5245cd to your computer and use it in GitHub Desktop.
Vue.component('tasks', {
template: '#tasks-template',
created: function () {
this.fetchTaskList()
},
methods: {
fetchTaskList: function() {
this.$http.get('api/tasks'), function(tasks) {
this.list = tasks;
};
},
toggleCompletedFor: function(task) {
task.completed = ! task.completed;
},
isCompleted: function(task) {
return task.completed;
},
isInProgress: function(task) {
return ! this.isCompleted(task)
},
deleteTask: function(task) {
this.list.splice(this.list.indexOf(task), 1);
}
},
computed: {
remaining: function() {
var vm = this
return this.list.filter(this.isInProgress).length
}
}
});
new Vue({
el: '#app',
data: function () {
return {
list: null
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment