Skip to content

Commit dbc6161

Browse files
authored
Merge pull request #26 from kkj930/master
5B. Turn product into a `@Prop() product!: any` of `Product.vue`
2 parents e759b1b + 5ecdbeb commit dbc6161

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

cli-socks/src/components/Product.vue

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,7 @@ import ProductReview from './ProductReview.vue';
6868
export 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

cli-socks/src/store.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff 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

cli-socks/src/views/Home.vue

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<template>
22
<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>
58

69
<div class="cart">
710
{{ cart.length }}
@@ -24,18 +27,11 @@ import { ProductModel } from '../models';
2427
})
2528
export default class Home extends Vue {
2629
27-
products: ProductModel[] = [];
2830
premium = true;
2931
cart: string[] = [];
3032
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;
3935
}
4036
4137
updateCart(product: any) {

0 commit comments

Comments
 (0)