diff --git a/index.html b/index.html index 2e7d6ac..6c61f3b 100644 --- a/index.html +++ b/index.html @@ -20,7 +20,8 @@
-

{{ product }}

+

{{ title }}

+

In Stock

Out of Stock

+ @mouseover="updateVariant(index)" + class="color-circle" + :style="{ backgroundColor: variant.color }"> +
+ diff --git a/main.js b/main.js index 7470f07..0d55fb7 100644 --- a/main.js +++ b/main.js @@ -4,12 +4,11 @@ const app = Vue.createApp({ cart:0, product: 'Socks', brand: 'Vue Mastery', - image: './assets/images/socks_blue.jpg', - inStock: false, + selectedVariant: 0, details: ['50% cotton', '30% wool', '20% polyester'], 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', quantity: 50 }, + { id: 2235, color: 'blue', image: './assets/images/socks_blue.jpg', quantity: 0 }, ] } }, @@ -17,8 +16,19 @@ const app = Vue.createApp({ 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 } } })