-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01-Socks.html
127 lines (90 loc) · 2.79 KB
/
01-Socks.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
<!-- https://www.vuemastery.com -->
<html>
<head>
<script src="https://unpkg.com/vue"></script>
<link href="./assets/style.css" rel="stylesheet">
<link href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" rel="stylesheet">
<title>Basic Socks</title>
</head>
<body>
<div id="app">
<div class="nav-bar"><h1>Basic Socks</h1></div>
<div class="product">
<div class="product-image">
<img v-bind:src="image" :title="imageTitle">
<!-- Attribute Shorthands -->
<!-- :src, :alt, :title, :class, :style, :disabled -->
</div>
<div class="product-info">
<!-- Binding -->
<h1>{{ product }}</h1>
<!-- Conditionals -->
<div>
<!-- Falsey will not include in DOM -->
<p v-if="inventory > 10">In Stock</p>
<p v-else-if="inventory">Almost sold out</p>
<p v-else>Out of Stock</p>
<!-- Render with display: none -->
<p v-show="inventory < 0">Wuuk?</p>
</div>
<!-- Events -->
<button
v-on:click="cart++; inventory--"
:disabled="!inventory"
class="add-to-cart"
:class="inventory ? '' : 'disabledButton'"
>
<!-- Method: addToCart -->
Add to Cart
</button>
<div class="cart">
{{ cart }}
<i class="fas fa-shopping-cart"></i>
</div>
<!-- Loops -->
<div v-for="variant in variants"
:key="variant.id"
class="color-box"
:style="{backgroundColor: variant.color}"
@mouseover="setImage(variant.color, $event)"
></div>
</div>
</div>
</div>
<a href="00-Hello.html" class="prev">
<i class="fas fa-arrow-left"></i> moving back
</a>
<a href="02-ComputedSocks.html" class="next">
moving on <i class="fas fa-arrow-right"></i>
</a>
</body>
</html>
<script type="text/javascript">
Vue.createApp({
data() {
return {
product: 'Socks',
image: './assets/socks-green.jpg',
imageTitle: 'Green Socks',
variants: [
{id: 1, color: 'green'},
{id: 2, color: 'blue'}
],
inventory: 3,
cart: 0
};
},
methods: {
addToCart() {
this.cart++;
this.inventory--;
},
setImage(color, event) {
console.log('Vue instance with data and methods', this, event);
this.image = `./assets/socks-${color}.jpg`;
}
}
}).mount('#app');
</script>
<!-- livereload -->
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>