-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (31 loc) · 850 Bytes
/
app.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
const { createApp } = Vue;
createApp({
data() {
return {
items: [],
task: "",
};
},
methods: {
getId() {
return this.items.length ? this.items[this.items.length - 1].id + 1 : 1;
},
add() {
this.items.push({ name: this.task, id: this.getId(), completed: false });
this.task = "";
},
completeTask(id) {
const items = this.items.map(item => {
if (item.id === id) {
return { ...item, completed: !item.completed };
}
return item;
});
this.items = items
},
remove(id) {
const items = this.items.filter(item => item.id !== id);
this.items = items;
}
}
}).mount('#app');