Vue
by flek
HTML
<div id="app">
<input
type="text"
placeholder="what needs to be done?"
v-on:keydown="keydownHandler"
/>
<h2>Todos:</h2>
<ol>
<li v-for="todo in todos" :key="todo">
<label>
<input
type="checkbox"
v-on:change="check(todo)" />
{{ todo }}
<button v-on:click="remove(todo)">remove</button>
</label>
</li>
</ol>
<h2>Dones:</h2>
<ol>
<li v-for="done in dones">
<del>{{ done }}</del>
</li>
<button v-if="dones.length" v-on:click="clear">clear</button>
</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: [
"Learn JavaScript",
"Learn Vue",
"Build something awesome"
],
dones: []
},
methods: {
keydownHandler: function(event) {
if (event.which === 13) {
this.enter(event.target);
}
},
enter: function enter(input) {
this.add(input.value);
input.value = '';
},
add: function(todo) {
this.todos.unshift(todo);
},
remove: function(todo) {
this.todos = this.todos.filter(t => t !== todo)
},
check: function(todo) {
this.remove(todo);
this.dones.push(todo);
},
clear: function() {
this.dones = [];
}
}
})