-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (38 loc) · 1.03 KB
/
script.js
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
Vue.createApp({
data() {
return {
filter: "all",
newTodo: "",
todos: [
{ description: "learnCss", checked: false },
{ description: "Learn Html", checked: true },
{ description: "Learn Javascript", checked: false },
{ description: "Learn Dancing", checked: true },
{ description: "Learn Soccer", checked: false },
],
};
},
methods: {
deleteFinishedTask() {
this.todos = this.todos.filter((todo) => !todo.checked);
},
addTodo() {
if (this.newTodo.length > 0) {
const newTodo = { description: this.newTodo, checked: false };
this.todos.push(newTodo);
this.newTodo = "";
}
},
},
computed: {
filteredTodos() {
if (this.filter === "all") {
return this.todos;
} else if (this.filter === "open") {
return this.todos.filter((todo) => !todo.checked);
} else if (this.filter === "done") {
return this.todos.filter((todo) => todo.checked);
}
},
},
}).mount("#app");