L8
This commit is contained in:
parent
df8fcd0ab6
commit
c18a7e0486
97
index.html
97
index.html
@ -1,50 +1,61 @@
|
|||||||
<!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.11/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">
|
|
||||||
<img v-bind:src="image">
|
|
||||||
</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 v-bind:src="image" />
|
||||||
@mouseover="updateImage(variant.image)"
|
</div>
|
||||||
:style="{ backgroundColor: variant.color }"></div>
|
<div class="product-info">
|
||||||
<button class="button" :class="{ disabledButton: !inStock }" :disabled="!inStock" v-on:click="addToCart">Add to Cart</button>
|
<h1>{{ title }}</h1>
|
||||||
</div>
|
<p v-if="variants[selectedVariant].onSale">
|
||||||
</div>
|
{{ sale }}
|
||||||
</div>
|
</p>
|
||||||
</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, index) in variants"
|
||||||
|
:key="variant.id"
|
||||||
|
@mouseover="updateVariant(index)"
|
||||||
|
class="color-circle"
|
||||||
|
:style="{ backgroundColor: variant.color }"
|
||||||
|
></div>
|
||||||
|
<button
|
||||||
|
class="button"
|
||||||
|
:class="{ disabledButton: !inStock }"
|
||||||
|
:disabled="!inStock"
|
||||||
|
v-on: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>
|
||||||
|
|||||||
76
main.js
76
main.js
@ -1,24 +1,54 @@
|
|||||||
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'],
|
selectedVariant: 0,
|
||||||
variants: [
|
details: ["50% cotton", "30% wool", "20% polyester"],
|
||||||
{ id: 2234, color: 'green', image: './assets/images/socks_green.jpg' },
|
variants: [
|
||||||
{ id: 2235, color: 'blue', image: './assets/images/socks_blue.jpg' },
|
{
|
||||||
]
|
id: 2234,
|
||||||
}
|
color: "green",
|
||||||
},
|
image: "./assets/images/socks_green.jpg",
|
||||||
methods: {
|
quantity: 50,
|
||||||
addToCart() {
|
onSale: true,
|
||||||
this.cart += 1
|
},
|
||||||
},
|
{
|
||||||
updateImage(variantImage) {
|
id: 2235,
|
||||||
this.image = variantImage
|
color: "blue",
|
||||||
}
|
image: "./assets/images/socks_blue.jpg",
|
||||||
}
|
quantity: 0,
|
||||||
})
|
onSale: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
addToCart() {
|
||||||
|
this.cart += 1;
|
||||||
|
},
|
||||||
|
updateImage(variantImage) {
|
||||||
|
this.image = variantImage;
|
||||||
|
},
|
||||||
|
updateVariant(index) {
|
||||||
|
this.selectedVariant = index;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
title() {
|
||||||
|
return this.brand + " " + this.product;
|
||||||
|
},
|
||||||
|
image() {
|
||||||
|
return this.variants[this.selectedVariant].image;
|
||||||
|
},
|
||||||
|
inStock() {
|
||||||
|
return this.variants[this.selectedVariant].quantity;
|
||||||
|
},
|
||||||
|
sale() {
|
||||||
|
return this.brand + " " + this.product + " is on sale";
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user