File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
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+
2434export 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: {
You can’t perform that action at this time.
0 commit comments