12
12
</h1 >
13
13
14
14
<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 >
17
17
<p v-else >Out of Stock</p >
18
18
</div >
19
19
22
22
23
23
<button
24
24
@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']"
27
27
>
28
28
Add to Cart
29
29
</button >
@@ -58,8 +58,8 @@ export default class Product extends Vue {
58
58
brand: " Vue" ,
59
59
price: 5 ,
60
60
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 }
63
63
],
64
64
inventory: 3 ,
65
65
reviews: []
@@ -83,9 +83,8 @@ export default class Product extends Vue {
83
83
}
84
84
85
85
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 });
89
88
}
90
89
91
90
addReview(review : any ) {
0 commit comments