Compare commits
No commits in common. "c18a7e048633ed539c03f7f8212fe51d16992492" and "c3db9998f89e92700cb0dff0eedc01db9149f60d" have entirely different histories.
c18a7e0486
...
c3db9998f8
31
index.html
31
index.html
@ -6,7 +6,7 @@
|
|||||||
<!-- 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.0-beta.12/dist/vue.global.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
@ -17,13 +17,12 @@
|
|||||||
<div class="product-display">
|
<div class="product-display">
|
||||||
<div class="product-container">
|
<div class="product-container">
|
||||||
<div class="product-image">
|
<div class="product-image">
|
||||||
<img v-bind:src="image" />
|
<!-- solution -->
|
||||||
|
<img :class="{ 'out-of-stock-img': !inStock }" v-bind:src="image">
|
||||||
|
<!-- solution -->
|
||||||
</div>
|
</div>
|
||||||
<div class="product-info">
|
<div class="product-info">
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ product }}</h1>
|
||||||
<p v-if="variants[selectedVariant].onSale">
|
|
||||||
{{ sale }}
|
|
||||||
</p>
|
|
||||||
<p v-if="inStock">In Stock</p>
|
<p v-if="inStock">In Stock</p>
|
||||||
<p v-else>Out of Stock</p>
|
<p v-else>Out of Stock</p>
|
||||||
<ul>
|
<ul>
|
||||||
@ -31,20 +30,12 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-for="(variant, index) in variants"
|
|
||||||
:key="variant.id"
|
|
||||||
@mouseover="updateVariant(index)"
|
|
||||||
class="color-circle"
|
class="color-circle"
|
||||||
:style="{ backgroundColor: variant.color }"
|
v-for="variant in variants"
|
||||||
></div>
|
:key="variant.id"
|
||||||
<button
|
@mouseover="updateImage(variant.image)"
|
||||||
class="button"
|
:style="{ backgroundColor: variant.color }"></div>
|
||||||
:class="{ disabledButton: !inStock }"
|
<button class="button" :class="{ disabledButton: !inStock }" :disabled="!inStock" v-on:click="addToCart">Add to Cart</button>
|
||||||
:disabled="!inStock"
|
|
||||||
v-on:click="addToCart"
|
|
||||||
>
|
|
||||||
Add to Cart
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -55,7 +46,7 @@
|
|||||||
|
|
||||||
<!-- Mount App -->
|
<!-- Mount App -->
|
||||||
<script>
|
<script>
|
||||||
const mountedApp = app.mount("#app");
|
const mountedApp = app.mount('#app')
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
58
main.js
58
main.js
@ -2,53 +2,23 @@ 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,
|
||||||
selectedVariant: 0,
|
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: 2234,
|
{ id: 2235, color: 'blue', image: './assets/images/socks_blue.jpg' },
|
||||||
color: "green",
|
]
|
||||||
image: "./assets/images/socks_green.jpg",
|
}
|
||||||
quantity: 50,
|
|
||||||
onSale: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2235,
|
|
||||||
color: "blue",
|
|
||||||
image: "./assets/images/socks_blue.jpg",
|
|
||||||
quantity: 0,
|
|
||||||
onSale: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addToCart() {
|
addToCart() {
|
||||||
this.cart += 1;
|
this.cart += 1
|
||||||
},
|
},
|
||||||
updateImage(variantImage) {
|
updateImage(variantImage) {
|
||||||
this.image = 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