forked from vueschool/vuejs-3-fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
89 lines (85 loc) · 2.37 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Shopping List App</title>
<link rel="stylesheet" href="main.css">
</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"
type="text" v-model="newItem" placeholder = "Add an Item">
<label>
<input type="checkbox" v-model="newItemHighPriority">
High Priority
</label>
<button
@click="saveItem"
class="btn btn-primary">
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="static-class"
:class="{strikeout: item.purchased, priority: item.highPriority}"
>
{{item.label}}
</li>
</ul>
</div>
<script src="https://unpkg.com/vue@3"></script>
<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 = false
},
doEdit(editing){
this.editing = editing
this.newItem = ""
this.newItemHighPriority = false
},
togglePurchased(item){
item.purchased = !item.purchased
}
}
}).mount('#shopping-list')
</script>
</body>
</html>