1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| el: '#app',
data: {
steps: [
{ name: 'Hello Vue!', completed: false },
{ name: 'Hello World!', completed: false }
],
newStep: ''
},
mounted: function(){
this.fetchSteps();
},
methods: {
fetchSteps: function(){
this.$http.get('/tasks/2/steps').then((response) => {
// success
Vue.set(this, 'steps', response.body);
}, (response) => {
// error
response.status;
});
},
addStep: function(){
this.steps.push({ name: this.newStep, completed: false });
this.newStep = '';
},
complete: function(step){
step.completed = true;
},
removeStep: function(step){
var index = this.steps.indexOf(step);
this.steps.splice(index, 1);
},
editStep: function(step){
this.removeStep(step);
this.newStep = step.name;
this.$refs.newStep.focus();
},
toggleComplete: function(step){
step.completed = false;
},
completeAll: function(){
this.steps.forEach(function(step){
step.completed = true;
});
},
clearComplete: function(){
// this.steps = [];k
this.steps = this.steps.filter(function(step){
return !step.completed;
});
}
},
computed: {
inProcess: function(){
return this.steps.filter(function(step){
if (step.completed == false) return step;
})
},
processed: function(){
return this.steps.filter(function(step){
if (step.completed == true) return step;
})
},
completions: function(){
return this.steps.filter(function(step){
return step.completed;
});
},
remaings: function(){
return this.steps.filter(function(step){
return !step.completed;
});
}
} |