Compare commits
4 Commits
c3db9998f8
...
025dc924ab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
025dc924ab | ||
|
|
dbf00bb4a3 | ||
|
|
d727eed0c9 | ||
|
|
094670e2a9 |
117
index.html
117
index.html
@ -1,52 +1,79 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>Vue Mastery</title>
|
<title>Vue Mastery</title>
|
||||||
<!-- Import Styles -->
|
<!-- Import Styles -->
|
||||||
<link rel="stylesheet" href="./assets/styles.css" />
|
<link rel="stylesheet" href="./assets/styles.css" />
|
||||||
<!-- Import Vue.js -->
|
<!-- Import Vue.js -->
|
||||||
<script src="https://unpkg.com/vue@3.0.0-beta.12/dist/vue.global.js"></script>
|
<script src="https://unpkg.com/vue@3.0.11/dist/vue.global.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="nav-bar"></div>
|
<div class="nav-bar"></div>
|
||||||
|
|
||||||
<div class="cart">Cart({{ cart }})</div>
|
<div class="cart">Cart({{ cart }})</div>
|
||||||
|
|
||||||
<div class="product-display">
|
|
||||||
<div class="product-container">
|
|
||||||
<div class="product-image">
|
|
||||||
<!-- solution -->
|
|
||||||
<img :class="{ 'out-of-stock-img': !inStock }" v-bind:src="image">
|
|
||||||
<!-- solution -->
|
|
||||||
</div>
|
|
||||||
<div class="product-info">
|
|
||||||
<h1>{{ product }}</h1>
|
|
||||||
<p v-if="inStock">In Stock</p>
|
|
||||||
<p v-else>Out of Stock</p>
|
|
||||||
<ul>
|
|
||||||
<li v-for="detail in details">{{ detail }}</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<div
|
<div class="product-display">
|
||||||
class="color-circle"
|
<div class="product-container">
|
||||||
v-for="variant in variants"
|
<div class="product-image">
|
||||||
:key="variant.id"
|
<img
|
||||||
@mouseover="updateImage(variant.image)"
|
:class="{ 'out-of-stock-img': !inStock }"
|
||||||
:style="{ backgroundColor: variant.color }"></div>
|
v-bind:src="image"
|
||||||
<button class="button" :class="{ disabledButton: !inStock }" :disabled="!inStock" v-on:click="addToCart">Add to Cart</button>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="product-info">
|
||||||
</div>
|
<h1>{{ product }}</h1>
|
||||||
</div>
|
<p v-if="inStock">In Stock</p>
|
||||||
|
<p v-else>Out of Stock</p>
|
||||||
|
<ul>
|
||||||
|
<li v-for="detail in details">{{ detail }}</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<!-- Import App -->
|
<div
|
||||||
<script src="./main.js"></script>
|
v-for="variant in variants"
|
||||||
|
:key="variant.id"
|
||||||
|
@click="updateImage(variant.image)"
|
||||||
|
class="color-circle"
|
||||||
|
:style="{ backgroundColor: variant.color }"
|
||||||
|
></div>
|
||||||
|
<button
|
||||||
|
:class="[inStock ? '' : 'disabledButton']"
|
||||||
|
:disabled="!inStock"
|
||||||
|
class="button"
|
||||||
|
@click="addToCart"
|
||||||
|
>
|
||||||
|
Add to Cart
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Mount App -->
|
<!-- Import App -->
|
||||||
<script>
|
<script src="./main.js"></script>
|
||||||
const mountedApp = app.mount('#app')
|
|
||||||
</script>
|
<!-- Mount App -->
|
||||||
</body>
|
<script>
|
||||||
|
const mountedApp = app.mount("#app");
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.color-circle {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
margin-top: 8px;
|
||||||
|
border: 2px solid #d8d8d8;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.color-circle:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.disabledButton {
|
||||||
|
background-color: #d8d8d8;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
54
main.js
54
main.js
@ -1,24 +1,32 @@
|
|||||||
const app = Vue.createApp({
|
const app = Vue.createApp({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
cart:0,
|
cart: 0,
|
||||||
product: 'Socks',
|
product: "Socks",
|
||||||
brand: 'Vue Mastery',
|
brand: "Vue Mastery",
|
||||||
image: './assets/images/socks_blue.jpg',
|
image: "./assets/images/socks_blue.jpg",
|
||||||
inStock: false,
|
inStock: false,
|
||||||
details: ['50% cotton', '30% wool', '20% polyester'],
|
details: ["50% cotton", "30% wool", "20% polyester"],
|
||||||
variants: [
|
variants: [
|
||||||
{ id: 2234, color: 'green', image: './assets/images/socks_green.jpg' },
|
{
|
||||||
{ id: 2235, color: 'blue', image: './assets/images/socks_blue.jpg' },
|
id: 2234,
|
||||||
]
|
color: "green",
|
||||||
}
|
image: "./assets/images/socks_green.jpg",
|
||||||
},
|
},
|
||||||
methods: {
|
{
|
||||||
addToCart() {
|
id: 2235,
|
||||||
this.cart += 1
|
color: "blue",
|
||||||
},
|
image: "./assets/images/socks_blue.jpg",
|
||||||
updateImage(variantImage) {
|
},
|
||||||
this.image = variantImage
|
],
|
||||||
}
|
};
|
||||||
}
|
},
|
||||||
})
|
methods: {
|
||||||
|
addToCart() {
|
||||||
|
this.cart += 1;
|
||||||
|
},
|
||||||
|
updateImage(variantImage) {
|
||||||
|
this.image = variantImage;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user