-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
83 lines (79 loc) · 3.53 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Vue Todo</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css"/>
<script src="https://kit.fontawesome.com/74b0d0c0f1.js" crossorigin="anonymous" defer></script>
<style type="text/css">
.strikeout {
text-decoration:line-through;
}
</style>
</head>
<body>
<div id="app" class="d-flex justify-content-center mt-4">
<div class="card w-25">
<div class="card-header text-center">Simple Vue Todo</div>
<div class="card-body">
<div class="form-group d-flex">
<input v-model="task" type="text" class="form-control" placeholder="type in your task">
<button @click="addTodo" class="btn btn-outline-primary ml-2">Create</button>
</div>
<ul class="navbar-nav">
<li v-for="(todo, index) in todos" :key="todo.id" class="nav-item d-flex justify-content-around border-bottom">
<input @change="setComplete(index)" type="checkbox" class="mt-3 border border-success">
<a href="#" v-bind:class="{ 'strikeout': todo.isComplete === 1, '': todo.isComplete === 0 }" class="nav-link">{{ todo.text }}</a>
<a @click.prevent="removeItem(index)" href="#" class="text-danger mt-2">x</a>
</li>
</ul>
</div>
<div class="card-footer">
<p class="text-center text-muted" style="font-size:0.8em">created by Sarmen Boyadjian</p>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script>
let app = new Vue({
el: '#app',
data: {
task: '',
todos: [
{ id:1, text:'todo item 1', isComplete: 0 },
{ id:2, text:'todo item 2', isComplete: 0 },
{ id:3, text:'todo item 3', isComplete: 0 },
{ id:4, text:'todo item 4', isComplete: 0 },
{ id:5, text:'todo item 5', isComplete: 0 },
],
},
methods: {
addTodo: function() {
this.todos.push({
id: this.todoLastItem.id + 1,
text: this.task,
isComplete: 0
});
this.task = '';
},
removeItem: function(index) {
if(confirm('Are you sure you want to delete that?'))
{
this.$delete(this.todos, index);
}
},
setComplete: function(index) {
this.todos[index].isComplete = 1
},
},
computed: {
todoLastItem: function() {
return this.todos.slice(-1)[0];
}
}
});
</script>
</body>
</html>