-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo.js
More file actions
66 lines (66 loc) · 1.89 KB
/
todo.js
File metadata and controls
66 lines (66 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var vm=new Vue({
el:'#app',
directives:{
focus:function (el,bindings) {
if(bindings.value)
el.focus();
}
},
data: {
todoList:[{isSelected:false,title:'睡觉'},
{isSelected:false,title:'睡觉'}],
title:'',
cur:'',
hash:''
},
created:function(){
this.todoList=JSON.parse(localStorage.getItem('data'))||this.todoList;
this.hash=window.location.hash.slice(2)||'all';
window.addEventListener('hashchange', ()=> {
this.hash=window.location.hash.slice(2);
},false);
},
watch:{
todoList:{
handler:function(){
localStorage.setItem('data',JSON.stringify(this.todoList));
},deep:true
}
},
methods:{
add:function () {
this.todoList.push({isSelected:false,title:this.title});
this.title='';
},
remove:function (todo) {
this.todoList=this.todoList.filter(item=>item!==todo);
},
rember:function (todo) {
this.cur=todo;
},
cancel:function () {
this.cur='';
}
},
computed:{
count:function () {
return this.todoList.filter(item=>item.isSelected==false).length;
},
newtodoList:function () {
if(this.hash==='all'){
return this.newtodoList=this.todoList;
}
if(this.hash==='finish'){
return this.newtodoList=this.todoList.filter(function (item) {
return item.isSelected==true;
})
}
if(this.hash==='unfinish'){
return this.newtodoList=this.todoList.filter(function (item) {
return item.isSelected==false;
})
return this.newtodoList=this.todoList;
}
}
}
})