File tree Expand file tree Collapse file tree 3 files changed +14
-32
lines changed Expand file tree Collapse file tree 3 files changed +14
-32
lines changed Original file line number Diff line number Diff line change @@ -68,18 +68,7 @@ import ProductReview from './ProductReview.vue';
68
68
export default class Product extends Vue {
69
69
@Prop ({default: false }) private premium! : boolean ;
70
70
@Prop () private cartLength! : number ;
71
-
72
- product = {
73
- name: " Vue Socks" ,
74
- brand: " Vue" ,
75
- price: 5 ,
76
- variants: [
77
- {id: 1 , color: " green" , inventory: 3 },
78
- {id: 2 , color: " blue" , inventory: 5 }
79
- ],
80
- inventory: 3 ,
81
- reviews: []
82
- };
71
+ @Prop () private product! : any ;
83
72
84
73
selectedVariantIndex = 0 ;
85
74
Original file line number Diff line number Diff line change @@ -9,31 +9,28 @@ const productList = [{
9
9
brand : "Vue" ,
10
10
price : 5 ,
11
11
variants : [
12
- { id : 1 , color : "green" } ,
13
- { id : 2 , color : "blue" }
12
+ { id : 1 , color : "green" , inventory : 4 } ,
13
+ { id : 2 , color : "blue" , inventory : 4 }
14
14
] ,
15
- inventory : 3 ,
16
15
reviews : [ ]
17
16
} ,
18
17
{
19
18
name : "Angular Socks" ,
20
- brand : "angular " ,
19
+ brand : "Angular " ,
21
20
price : 15 ,
22
21
variants : [
23
- { id : 1 , color : "red" } ,
24
- { id : 2 , color : "blue" }
22
+ { id : 1 , color : "red" , inventory : 4 } ,
23
+ { id : 2 , color : "blue" , inventory : 4 }
25
24
] ,
26
- inventory : 3 ,
27
25
reviews : [ ]
28
26
} ,
29
27
{
30
28
name : "npm Socks" ,
31
29
brand : "npm" ,
32
30
price : 3 ,
33
31
variants : [
34
- { id : 1 , color : "red" } ,
32
+ { id : 1 , color : "red" , inventory : 4 } ,
35
33
] ,
36
- inventory : 3 ,
37
34
reviews : [ ]
38
35
} ] ;
39
36
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div >
3
- <!-- <Product :premium="premium" @add-to-cart="updateCart" @remove-from-cart="removeFromCart" :cartLength="cart.length"></Product>-->
4
- <ProductLine v-for =" k in products" :key =" k.name" :product =" k" ></ProductLine >
3
+
4
+ <ProductLine v-for =" product in products"
5
+ :key =" product.brand"
6
+ :product =" product"
7
+ ></ProductLine >
5
8
6
9
<div class =" cart" >
7
10
{{ cart.length }}
@@ -24,18 +27,11 @@ import { ProductModel } from '../models';
24
27
})
25
28
export default class Home extends Vue {
26
29
27
- products: ProductModel [] = [];
28
30
premium = true ;
29
31
cart: string [] = [];
30
32
31
- constructor () {
32
- super ();
33
- const product1 = new ProductModel ();
34
- product1 .name = " product1" ;
35
- const product2 = new ProductModel ();
36
- product2 .name = " product2" ;
37
- this .products .push (product1 );
38
- this .products .push (product2 );
33
+ get products() {
34
+ return this .$store .state .products ;
39
35
}
40
36
41
37
updateCart(product : any ) {
You can’t perform that action at this time.
0 commit comments