Vue
HTML
<div id="app">
<h2>Todos:</h2>
<ol>
<li v-for="todo in todos">
<label>
<input type="checkbox"
disabled
v-on:change="toggle(todo)"
v-bind:checked="todo.done">
<del v-if="todo.done">
{{ todo.text }}
</del>
<span v-else>
{{ todo.text }}
{{ todo.half }}
{{ todo.timeout }}
</span>
</label>
</li>
</ol>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}
Vue
new Vue({
el: "#app",
data: {
todos: [
{ text: "Learn JavaScript", half: false, done: false, timeout: Math.random()*5000 },
{ text: "Learn Vue", half: false, done: false, timeout: Math.random()*5000 },
{ text: "Play around in JSFiddle", half: false, done: false, timeout: Math.random()*5000 },
{ text: "Build something awesome", half: false, done: false, timeout: Math.random()*5000 }
]
},
methods: {
delayedHalf(todo) {
return new Promise((resolve) => {
setTimeout(()=>{
todo.half = true;
resolve();
}, todo.timeout);
})
},
delayedDone(todo) {
return new Promise((resolve) => {
setTimeout(()=>{
todo.done = true;
resolve();
}, todo.timeout);
})
}
},
async mounted() {
await Promise.all(this.todos.map(async todo => {
await this.delayedHalf(todo, false);
return this.delayedDone(todo, true);
}));
alert('all done');
}
})