-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
146 lines (132 loc) · 4.91 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html lang="es">
<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>NSMichelJ - App de tareas</title>
<link rel="stylesheet" href="./static/css/bulma.min.css">
<link rel="shortcut icon" href="./static/img/tasks.svg" type="image/svg">
<style>
.columns {
margin: 0;
}
.hero{
display: block;
}
</style>
</head>
<body>
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="container">
<div class="navbar-brand">
<span class="navbar-item">
<img src="./static/img/tasks.svg" alt="Logo" width="112" height="28">
</span>
</div>
</div>
</nav>
<div id="app">
<section class="hero is-primary mb-4">
<div class="container">
<div class="hero-body columns">
<div class="column">
<div class="box">
<form>
<div class="control">
<textarea v-model="task" class="textarea has-fixed-size" placeholder="Escribe tu tarea..."></textarea>
<div class="field is-grouped is-grouped-centered">
<button class="mt-4 button is-success is-rounded" v-on:click.prevent="saveTask">Guardar Tarea</button>
</div>
</div>
</form>
</div>
</div>
<div class="column has-text-centered">
<p class="title">
App de tareas con VueJS y Bulma
</p>
<p class="subtitle is-6">
by
<a href="https://github.com/NSMichelJ">
NSMichelJ
</a>
</p>
</div>
</div>
</div>
</section>
<div class="container">
<div class="columns is-multiline is-mobile">
<div v-for="task in tasks" class="column">
<div class="notification ">
<button v-on:click="deleteTask(task.id)" class="delete"></button>
{{task.text}}
</div>
</div>
</div>
</div>
</div>
<script src="./static/js/vue.min.js"></script>
<script>
const vm = new Vue({
el: '#app',
data: {
task: '',
tasks: []
},
created() {
this.getTask()
},
methods: {
setItemInLocalStorage(data){
localStorage.setItem('task-app-data', JSON.stringify(data))
},
getTask: function () {
tasks = JSON.parse(localStorage.getItem('task-app-data'))
if (tasks != null) {
this.tasks = tasks[1]
if (tasks[1].length == 0) {
tasks[0] = 0
this.setItemInLocalStorage(tasks)
}
}
},
saveTask: function () {
if (this.task != '') {
task = {
id: 0,
text: this.task
}
tasks = JSON.parse(localStorage.getItem('task-app-data'))
if (tasks != null) {
task.id = tasks[0] + 1
tasks[0] += 1
tasks[1].push(task)
this.setItemInLocalStorage(tasks)
} else {
tasks = [0, []]
tasks[1].push(task)
this.setItemInLocalStorage(tasks)
}
this.getTask()
this.task = ''
}
},
deleteTask: function (id) {
tasks = JSON.parse(localStorage.getItem('task-app-data'))
new_tasks = []
tasks[1].forEach(task => {
if (task.id != id) {
new_tasks.push(task)
}
});
tasks[1] = new_tasks
this.setItemInLocalStorage(tasks)
this.getTask()
},
}
});
</script>
</body>
</html>