1818 </div >
1919
2020 <div >
21- <p v-if =" product .inventory > 10" >In Stock</p >
22- <p v-else-if =" product .inventory" >Almost sold out</p >
21+ <p v-if =" selectedVariant .inventory > 10" >In Stock</p >
22+ <p v-else-if =" selectedVariant .inventory" >Almost sold out</p >
2323 <p v-else >Out of Stock</p >
2424 </div >
2525
2828
2929 <button
3030 @click =" addToCart"
31- :disabled =" !product .inventory"
32- :class =" ['add-to-cart', product .inventory ? '' : 'disabledButton']"
31+ :disabled =" !selectedVariant .inventory"
32+ :class =" ['add-to-cart', selectedVariant .inventory ? '' : 'disabledButton']"
3333 >
3434 Add to Cart
3535 </button >
@@ -74,8 +74,8 @@ export default class Product extends Vue {
7474 brand: " Vue" ,
7575 price: 5 ,
7676 variants: [
77- {id: 1 , color: " green" },
78- {id: 2 , color: " blue" }
77+ {id: 1 , color: " green" , inventory: 3 },
78+ {id: 2 , color: " blue" , inventory: 5 }
7979 ],
8080 inventory: 3 ,
8181 reviews: []
@@ -99,9 +99,8 @@ export default class Product extends Vue {
9999 }
100100
101101 addToCart() {
102- this .product .inventory -- ;
103- const selectedVariant = this .product .variants [this .selectedVariantIndex ];
104- this .$emit (' add-to-cart' , {product: this .product , variant: selectedVariant });
102+ this .selectedVariant .inventory -- ;
103+ this .$emit (' add-to-cart' , {product: this .product , variant: this .selectedVariant });
105104 }
106105
107106 removeFromCart() {
0 commit comments