-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue_index.html
117 lines (114 loc) · 4.13 KB
/
vue_index.html
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://unpkg.com/vue@next"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="app">
<div class="header">
<div class="form">
<label for="title">Todolist</label>
<input type="form" id="title" placeholder="添加ToDo" v-model="todoitem" @keyup.enter="handleKeyUP">
</div>
</div>
<div class="content">
<div class="doing">
<h2>
正在进行
<span class="todocount">{{ todocount }}</span>
</h2>
<ol class="todolist">
<li v-for="item in todoList" :key="item.id" :id="item.id">
<input type="checkbox" @click="itemDone(item.id, item.flag)" :checked="item.flag">
<span>{{ item.content }}</span>
<button @click="itemClear(item.id, item.flag)" class="itemClear">-</button>
</li>
</ol>
</div>
<div class="done">
<h2>
已完成
<span class="donecount">{{ donecount }}</span>
</h2>
<ol class="donelist">
<li v-for="item in doneList" :key="item.id" :id="item.id">
<div>
<input type="checkbox" @click="itemDone(item.id, item.flag)" :checked="item.flag">
<span>{{ item.content }}</span>
<button @click="itemClear(item.id, item.flag)" class="itemClear">-</button>
</div>
</li>
</ol>
</div>
</div>
</div>
</body>
<script>
const app = Vue.createApp({
data(){
return {
todoitem: '',
todoList: [],
doneList: []
}
},
methods: {
handleKeyUP(){
const item = {
content: this.todoitem,
flag: false,
id: +new Date()
}
this.todoList.push(item);
},
itemDone(id, flag){
if(!flag){
for(let i = 0; i < this.todoList.length; i++){
if(this.todoList[i].id == id){
this.todoList[i].flag = !this.todoList[i].flag;
this.doneList.push(this.todoList.splice(i, 1)[0])
}
}
}else{
for(let i = 0; i < this.doneList.length; i++){
if(this.doneList[i].id == id){
this.doneList[i].flag = !this.doneList[i].flag;
this.todoList.push(this.doneList.splice(i, 1)[0])
}
}
}
},
itemClear(id, flag){
if(!flag){
for(let i = 0; i < this.todoList.length; i++){
if(this.todoList[i].id == id){
this.todoList[i].flag = !this.todoList[i].flag;
this.todoList.splice(i, 1);
}
}
}else{
for(let i = 0; i < this.doneList.length; i++){
if(this.doneList[i].id == id){
this.doneList[i].flag = !this.doneList[i].flag;
this.doneList.splice(i, 1);
}
}
}
}
},
computed: {
todocount(){
return this.todoList.length;
},
donecount(){
return this.doneList.length;
}
}
}).mount('#app');
</script>
</html>