1212 </h1 >
1313
1414 <div >
15- <p v-if =" product .inventory > 10" >In Stock</p >
16- <p v-else-if =" product .inventory" >Almost sold out</p >
15+ <p v-if =" selectedVariant .inventory > 10" >In Stock</p >
16+ <p v-else-if =" selectedVariant .inventory" >Almost sold out</p >
1717 <p v-else >Out of Stock</p >
1818 </div >
1919
2222
2323 <button
2424 @click =" addToCart"
25- :disabled =" !product .inventory"
26- :class =" ['add-to-cart', product .inventory ? '' : 'disabledButton']"
25+ :disabled =" !selectedVariant .inventory"
26+ :class =" ['add-to-cart', selectedVariant .inventory ? '' : 'disabledButton']"
2727 >
2828 Add to Cart
2929 </button >
@@ -58,8 +58,8 @@ export default class Product extends Vue {
5858 brand: " Vue" ,
5959 price: 5 ,
6060 variants: [
61- {id: 1 , color: " green" },
62- {id: 2 , color: " blue" }
61+ {id: 1 , color: " green" , inventory: 3 },
62+ {id: 2 , color: " blue" , inventory: 5 }
6363 ],
6464 inventory: 3 ,
6565 reviews: []
@@ -83,9 +83,8 @@ export default class Product extends Vue {
8383 }
8484
8585 addToCart() {
86- this .product .inventory -- ;
87- const selectedVariant = this .product .variants [this .selectedVariantIndex ];
88- this .$emit (' add-to-cart' , {product: this .product , variant: selectedVariant });
86+ this .selectedVariant .inventory -- ;
87+ this .$emit (' add-to-cart' , {product: this .product , variant: this .selectedVariant });
8988 }
9089
9190 addReview(review : any ) {
0 commit comments