-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
93 lines (89 loc) · 2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping List App</title>
<link rel="stylesheet" href="main.css">
<script src="https://unpkg.com/vue@3"></script>
</head>
<body>
<div id="shopping-list">
<div class="header">
<h1>{{ header || 'Welcome' }}</h1>
<button v-if="editing" @click="doEdit(false)" class="btn btn-cancel">Cancel</button>
<button v-else @click="doEdit(true)" class="btn btn-primary">Add Item</button>
</div>
<div v-if="editing" class="add-item-form">
<input
@keyup.enter="saveItem"
v-model="newItem"
type="text"
placeholder="Add an item" />
<label for="prioritybox">
<input id="prioritybox" type="checkbox" v-model="newItemHighPriority"> High Priority
</label>
<button
@click="saveItem"
class="btn btn-primary"
:disabled="newItem.length < 5"
>Save Item</button>
</div>
<p v-if="items.length === 0">Nice job! You've bought all your items</p>
<ul>
<li
v-for="item in reversedItems"
@click="togglePurchased(item)"
:key="item.id"
:class="[
{strikeout: item.purchased},
{priority: item.highPriority},
'static-class'
]"
>{{ item.label }}</li>
</ul>
</div>
</body>
<script>
const shoppingListApp = Vue.createApp({
data(){
return {
header: "Shopping List App",
editing: false,
newItem: '',
newItemHighPriority: false,
items: [
{id: 1, label: "10 party hats", purchased: true, highPriority: false},
{id: 2, label: "2 board games", purchased: true, highPriority: false},
{id: 3, label: "20 cups", purchased: false, highPriority: true},
]
}
},
computed:{
reversedItems(){
return [...this.items].reverse();
}
},
methods:{
saveItem(){
this.items.push({
id:this.items.length + 1,
label: this.newItem,
highPriority: this.newItemHighPriority
});
this.newItem = "";
this.newItemHighPriority = ""
},
doEdit(editing){
this.editing = editing;
this.newItem = "";
this.newItemHighPriority = ""
},
togglePurchased(item){
item.purchased = !item.purchased;
}
}
})
.mount('#shopping-list')
</script>
</html>