This commit is contained in:
bwbl 2026-01-13 15:16:00 +01:00
parent dbf00bb4a3
commit 025dc924ab
2 changed files with 103 additions and 65 deletions

View File

@ -17,7 +17,10 @@
<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"> <img
:class="{ 'out-of-stock-img': !inStock }"
v-bind:src="image"
/>
</div> </div>
<div class="product-info"> <div class="product-info">
<h1>{{ product }}</h1> <h1>{{ product }}</h1>
@ -30,9 +33,18 @@
<div <div
v-for="variant in variants" v-for="variant in variants"
:key="variant.id" :key="variant.id"
@mouseover="updateImage(variant.image)" @click="updateImage(variant.image)"
>{{ variant.color }}</div> class="color-circle"
<button class="button" @click="addToCart">Add to Cart</button> :style="{ backgroundColor: variant.color }"
></div>
<button
:class="[inStock ? '' : 'disabledButton']"
:disabled="!inStock"
class="button"
@click="addToCart"
>
Add to Cart
</button>
</div> </div>
</div> </div>
</div> </div>
@ -43,7 +55,25 @@
<!-- Mount App --> <!-- Mount App -->
<script> <script>
const mountedApp = app.mount('#app') const mountedApp = app.mount("#app");
</script> </script>
</body> </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>

34
main.js
View File

@ -2,23 +2,31 @@ 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",
},
{
id: 2235,
color: "blue",
image: "./assets/images/socks_blue.jpg",
},
],
};
}, },
methods: { methods: {
addToCart() { addToCart() {
this.cart += 1 this.cart += 1;
}, },
updateImage(variantImage) { updateImage(variantImage) {
this.image = variantImage this.image = variantImage;
} },
} },
}) });