-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
89 lines (87 loc) · 2.05 KB
/
App.vue
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
<template>
<div class="app">
<div class="container">
<div class="row header">
<form @submit.prevent="submitTodo" class="col s6 offset-s3">
<div class="input-field">
<i class="material-icons prefix grey-text">{{ list }}</i>
<textarea
v-model="newTodo"
id="icon_prefix2"
class="materialize-textarea grey-text"
/>
<label for="icon_prefix2">What do you want to do?</label>
</div>
<button class="btn waves-effect col s12">Add</button>
</form>
</div>
<div v-if="todos.length !== 0" class="row">
<ul class="collection col s6 offset-s3">
<li
class="collection-item grey darken-4"
v-for="todo in todos"
:key="todo.id"
>
<p>
<label>
<input
type="checkbox"
:checked="todo.done"
@change="todo.done = !todo.done"
/>
<span>{{ todo.title }}</span>
<span>
<a @click.prevent="deleteTodo(todo)">
<i class="material-icons right teal-text">delete</i>
</a>
</span>
</label>
</p>
</li>
</ul>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'app',
data() {
return {
todos: [],
newTodo: '',
};
},
watch: {
todos: {
handler() {
localStorage.todos = JSON.stringify(this.todos);
},
deep: true,
},
},
mounted() {
if (localStorage.todos) {
this.todos = JSON.parse(localStorage.todos);
}
},
methods: {
submitTodo() {
this.todos.push({
title: this.newTodo,
done: false,
});
this.newTodo = '';
},
deleteTodo(todo) {
const todoIndex = this.todos.indexOf(todo);
this.todos.splice(todoIndex, 1);
},
},
};
</script>
<style lang="scss">
.header {
margin-top: 20px;
}
</style>