-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
109 lines (109 loc) · 3.06 KB
/
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
<!DOCTYPE html>
<html lang="pt-br">
<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" />
<link rel="preload" href="style.css" as="style" />
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="externals.css" />
<link
rel="stylesheet"
href="node_modules/bootstrap-icons/font/bootstrap-icons.css"
/>
<title>TODO list with vue</title>
</head>
<body>
<div id="main">
<div id="list">
<h1>{{title}}</h1>
<div v-for="(x, y) in todo_items" id="items">
<label>{{x[0]}}</label>
<input @click="completeItem(y)" type="checkbox" :checked="(x[1])" />
<button class="rmv" @click="deleteItem(y)">
<i class="bi bi-trash-fill"></i>
</button>
</div>
<form :class="form_class">
<input v-model="list_item_raw" type="text" />
<button @click.prevent="addItem('add')">
<i class="bi bi-check"></i>
</button>
</form>
<button
v-html="addItemTooglerText"
class="bubbly-button"
@click.prevent="addItem('toogle')"
>
{{addItemTooglerText}}
</button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script type="text/javascript">
const vue = new Vue({
el: "#main",
data() {
return {
title: "TODO-LIST with Vue",
todo_items: [],
form_class: "hidden",
addItemTooglerText: "<i class='bi bi-plus'></i>",
list_item_raw: "",
};
},
methods: {
addItem(method) {
switch (method) {
case "toogle":
if (this.addItemTooglerText == "<i class='bi bi-x'></i>") {
this.addItemTooglerText = "<i class='bi bi-plus'></i>";
this.form_class = "hidden";
} else {
this.addItemTooglerText = "<i class='bi bi-x'></i>";
this.form_class = "visible";
}
break;
case "add":
let todo_items = this.todo_items;
list_item_raw = [this.list_item_raw, false];
todo_items.push(list_item_raw);
this.list_item_raw = "";
todo_items = JSON.stringify(todo_items);
localStorage.setItem("todo_items", todo_items);
break;
}
},
deleteItem(item) {
let todo_items = this.todo_items;
todo_items.splice(item, 1);
todo_items = JSON.stringify(todo_items);
localStorage.setItem("todo_items", todo_items);
},
completeItem(item) {
if (this.todo_items[item][1] === true) {
this.todo_items[item][1] = false;
localStorage.setItem(
"todo_items",
JSON.stringify(this.todo_items)
);
} else {
this.todo_items[item][1] = true;
localStorage.setItem(
"todo_items",
JSON.stringify(this.todo_items)
);
}
},
},
beforeMount() {
this.todo_items =
JSON.parse(localStorage.getItem("todo_items")) === null
? []
: JSON.parse(localStorage.getItem("todo_items"));
},
});
</script>
<script src="externals.js"></script>
</body>
</html>