-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo.html
138 lines (121 loc) · 5.38 KB
/
todo.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue To-Do</title>
<link rel="stylesheet" type="text/css" href="css/grid.css" media="screen">
<link rel="stylesheet" type="text/css" href="css/printstyle.css" media="print">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
</head>
<body>
<!-- This HTML5 main element was needed to keep the footer at the bottom of the page on mobile-->
<div id="main">
<!-- This HTML5 header element will contain a picture, title of the page, and the nav element -->
<header>
<figure>
<img src="images/todo.jpg" alt="Picture of checklist" title="Picture of checklist"
width="600" height="450"/>
<figcaption><span>Photo by <a href="https://unsplash.com/@glenncarstenspeters?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Glenn Carstens-Peters</a> on <a href="https://unsplash.com/s/photos/checklist?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a></span></span></figcaption>
</figure>
<h1>Vue To-Do</h1>
<!-- This HTML5 nav element will contain the nav bar -->
<nav>
<ul>
<li><a href="index.html">Home</a> </li>
<li><a href="academic.html">School</a> </li>
<li><a href="professional.html">Work</a> </li>
<li class="dropdown">
<a href="#">Play</a>
<ul>
<li><a href="hiking.html">Hiking</a></li>
<li><a href="music.html">Music</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="active">Apps</a>
<ul>
<li><a href="weather.html">Weather</a></li>
<li><a href="stocks.html">Stocks</a></li>
<li><a href="covid.html">Covid</a></li>
<li><a href="todo.html" class="active">To-Do</a></li>
<li><a href="reviews.html">Reviews</a></li>
</ul>
</li>
</ul>
</nav>
<hr>
</header>
<!-- This HTML5 section element will my article(s) for this page -->
<section style="background-color: #def5ff">
<h2>Vue To-Do App</h2>
<div id="app">
<form id="form" @submit.prevent="addToDo">
<input type="text" id="inputValue-todo" placeholder=" What do I need to do..." v-model="newToDo" autocomplete="off">
<input type="submit" value="Add" id="btn">
</form>
<div v-show="error" style="color:red">Entry cannot be blank!</div>
<ul id="todo-list">
<li v-for="(todo, index) in todos" :class="{done: todo.done}">
<span id="todo-item">{{todo.title}}</span>
<input class="todo-buttons" type="checkbox" v-model="todo.done" @click="markDone(index)">
<i class="fas fa-trash-alt todo-buttons" id="trash" @click="remove(index)"></i>
</li>
</ul>
</div>
</section>
<!--Include Vue-->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<!--Create Vue instance-->
<script>
var STORAGE_KEY = 'todo-storage';
var app = new Vue({
el: '#app',
data: {
newToDo: '',
todos: [],
error: false
},
created: function created() {
this.todos = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
window.console.log(this.todos);
},
methods: {
addToDo: function addToDo() {
if (this.newToDo.trim() === '') {
this.error = true;
} else {
this.todos.push({
title: this.newToDo,
done: false
});
this.newToDo = '';
this.error = false;
localStorage.setItem(STORAGE_KEY, JSON.stringify(this.todos));
}
},
remove: function remove(index) {
this.todos.splice(index, 1);
localStorage.setItem(STORAGE_KEY, JSON.stringify(this.todos));
},
markDone: function markDone(index) {
this.todos[index].done = !this.todos[index].done;
window.console.log(this.todos[index].title + ' = ' + this.todos[index].done);
localStorage.setItem(STORAGE_KEY, JSON.stringify(this.todos));
}
}
});
</script>
<!-- This HTML5 footer element will contain my name, email, and last updated date, as well as printed from line -->
<footer>
<div id="footer-left"><p>© 2020 Henry Choy</p></div>
<div id="footer-center"><p><a href="mailto:[email protected]">[email protected]</a></p></div>
<div id="footer-right"><p id="last-updated"></p></div>
<p class="printed-from">Printed from http://henrychoy.com/</p>
</footer>
</div>
<script>
// last updated in footer
document.getElementById("last-updated").textContent = "Last Updated: " + document.lastModified;
</script>
</body>
</html>