Skip to content

Commit 222a37e

Browse files
committed
Step 5 - Removing + Editing
1 parent 04399aa commit 222a37e

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/app.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
<ul>
66
<li v-repeat="todo : todos">
77
<input type="checkbox" v-model="todo.completed">
8-
<label>{{ todo.title }}</label>
8+
<label v-on="dblclick: todo.editing = true"
9+
v-show="!todo.editing">{{todo.title}}</label>
10+
<input v-model="todo.title"
11+
v-on="blur:save(todo), keyup:save(todo) | key 'enter'"
12+
v-show="todo.editing">
13+
<a v-on="click:remove(todo)">[x]</a>
914
</li>
1015
</ul>
1116
</template>
@@ -21,9 +26,19 @@ export default {
2126
add() {
2227
var value = this.input.trim();
2328
if (value) {
24-
this.todos.push({title: value, completed: false});
29+
this.todos.push({title: value, completed: false, editing: false});
2530
this.input = '';
2631
}
32+
},
33+
save(todo) {
34+
todo.editing = false;
35+
todo.title = todo.title.trim();
36+
if (!todo.title) {
37+
this.remove(todo);
38+
}
39+
},
40+
remove(todo) {
41+
this.todos.$remove(todo);
2742
}
2843
}
2944
};

0 commit comments

Comments
 (0)