-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathindex.html
74 lines (74 loc) · 2.88 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
<!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.toLocaleUpperCase() }}</h1>
<button v-if="state === 'default'" class="btn btn-primary" @click="changeState('edit')">Add Item</button>
<button v-else class="btn btn-cancel" @click="changeState('default')">Cancel Adding Item</button>
</div>
<div v-if="state === 'edit'" class="add-item-form">
<input v-model="newItem" type="text" placeholder="Add an item" @keyup.enter="saveItem">
<button class="btn btn-primary" :disabled="newItem.length === 0" @click="saveItem">Save Item</button>
</div>
<ul>
<li v-for="item in reversedItems" :class="{strikeout: item.purchased}" @click="togglePurchased(item)">{{ item.label }}</li>
</ul>
<p v-if="items.length === 0">Nice job! You've bought all your items.</p>
</div>
<script src="https://unpkg.com/vue"></script>
<script>
var shoppingList = new Vue({
el: '#shopping-list',
data: {
state: 'default',
header: 'shopping list app',
newItem: '',
items: [
{
label: '10 party hats',
purchased: false,
highPriority: false,
},
{
label: '2 board games',
purchased: true,
highPriority: false,
},
{
label: '20 cups',
purchased: false,
highPriority: false,
},
]
},
computed: {
reversedItems() {
return this.items.slice(0).reverse();
}
},
methods: {
saveItem: function() {
this.items.push({
label: this.newItem,
purchased: false,
});
this.newItem = '';
},
changeState: function(newState) {
this.state = newState;
this.newItem = '';
},
togglePurchased: function(item) {
item.purchased = !item.purchased;
}
}
})
</script>
</body>
</html>