Skip to content

Commit 7620ae9

Browse files
committed
Step 7 - Filters
1 parent 44b2a75 commit 7620ae9

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/app.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
v-model="input"
44
v-on="keyup:add | key 'enter'">
55
<ul>
6-
<li v-repeat="todo : todos">
6+
<li v-repeat="todo : filtered">
77
<input type="checkbox" v-model="todo.completed">
88
<label v-on="dblclick: todo.editing = true"
99
v-show="!todo.editing">{{todo.title}}</label>
@@ -17,18 +17,30 @@
1717
<strong>
1818
{{ remaining }} {{ remaining | pluralize 'item' }} remaining
1919
</strong>
20+
<a v-on="click: filter = 'all'">All</a>
21+
<a v-on="click: filter = 'active'">Active</a>
22+
<a v-on="click: filter = 'completed'">Completed</a>
2023
</div>
2124
</template>
2225

2326
<script>
27+
28+
var filters = {
29+
all: (todos) => todos,
30+
active: (todos) => todos.filter(todo => !todo.completed),
31+
completed: (todos) => todos.filter(todo => todo.completed)
32+
};
33+
2434
export default {
2535
data: {
2636
todos: [],
27-
input: ''
37+
input: '',
38+
filter: 'all'
2839
},
2940
3041
computed: {
31-
remaining() { return this.todos.filter(todo => !todo.completed).length; }
42+
remaining() { return filters.active(this.todos).length; },
43+
filtered() { return filters[this.filter](this.todos); }
3244
},
3345
3446
methods: {

0 commit comments

Comments
 (0)