File tree Expand file tree Collapse file tree 3 files changed +18
-22
lines changed
Expand file tree Collapse file tree 3 files changed +18
-22
lines changed Original file line number Diff line number Diff line change @@ -68,18 +68,7 @@ import ProductReview from './ProductReview.vue';
6868export default class Product extends Vue {
6969 @Prop ({default: false }) private premium! : boolean ;
7070 @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 ;
8372
8473 selectedVariantIndex = 0 ;
8574
Original file line number Diff line number Diff line change @@ -9,31 +9,28 @@ const productList = [{
99 brand : "Vue" ,
1010 price : 5 ,
1111 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 }
1414 ] ,
15- inventory : 3 ,
1615 reviews : [ ]
1716} ,
1817{
1918 name : "Angular Socks" ,
20- brand : "angular " ,
19+ brand : "Angular " ,
2120 price : 15 ,
2221 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 }
2524 ] ,
26- inventory : 3 ,
2725 reviews : [ ]
2826} ,
2927{
3028 name : "npm Socks" ,
3129 brand : "npm" ,
3230 price : 3 ,
3331 variants : [
34- { id : 1 , color : "red" } ,
32+ { id : 1 , color : "red" , inventory : 4 } ,
3533 ] ,
36- inventory : 3 ,
3734 reviews : [ ]
3835} ] ;
3936
Original file line number Diff line number Diff line change 11<template >
22 <div >
3- <Product :premium =" premium" @add-to-cart =" updateCart" @remove-from-cart =" removeFromCart" :cartLength =" cart.length" ></Product >
3+ <Product v-for =" product in products"
4+ :key =" product.brand"
5+ :premium =" premium"
6+ :product =" product"
7+ @add-to-cart =" updateCart"
8+ @remove-from-cart =" removeFromCart"
9+ :cartLength =" cart.length" ></Product >
410
511 <div class =" cart" >
612 {{ cart.length }}
@@ -22,6 +28,10 @@ export default class Home extends Vue {
2228 premium = true ;
2329 cart: string [] = [];
2430
31+ get products() {
32+ return this .$store .state .products ;
33+ }
34+
2535 updateCart(product : any ) {
2636 console .log (" Adding to cart:" , product );
2737 this .cart .push (product );
You can’t perform that action at this time.
0 commit comments