Skip to content

Commit 0e3f289

Browse files
committed
4B: added productlines
1 parent 8d6847b commit 0e3f289

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<template>
2+
<div>{{product.name}}
3+
<router-link :to="{ name: 'product', params: { id: product.name }}">Link</router-link>
4+
</div>
5+
</template>
6+
7+
8+
<script lang="ts">
9+
import { Component, Prop, Vue } from "vue-property-decorator";
10+
import { ProductModel } from '../models';
11+
12+
@Component({
13+
components: {
14+
}
15+
})
16+
17+
export default class ProductLine extends Vue {
18+
@Prop({default: undefined}) private product!: ProductModel;
19+
}
20+
</script>
21+
22+
<style scoped>
23+
24+
</style>

cli-socks/src/models.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export class ProductModel {
2+
name: string = "";
3+
brand: string = "";
4+
variants: [
5+
// {id: 1, color: "green"},
6+
// {id: 2, color: "blue"}
7+
] = [];
8+
inventory: number = 0;
9+
reviews: [] = [];
10+
}

cli-socks/src/router.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from "vue";
22
import Router from "vue-router";
33
import Home from "./views/Home.vue";
4+
import Product from "./components/Product.vue";
45

56
Vue.use(Router);
67

@@ -21,10 +22,11 @@ export default new Router({
2122
// which is lazy-loaded when the route is visited.
2223
component: () => import(/* webpackChunkName: "counter" */ "./views/Counter.vue")
2324
},
24-
// {
25-
// path: '/product/:id',
26-
// component: () => import(/* webpackChunkName: "productDetail" */ "./views/ProductPage.vue")
27-
// }
25+
{
26+
name: 'product',
27+
path: '/product/:id',
28+
component: Product
29+
}
2830
// Get id with: {{ $route.params.id }}
2931
// Example:
3032
// path: "/user/:username/post/:post_id"

cli-socks/src/views/Home.vue

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div>
3-
<Product :premium="premium" @add-to-cart="updateCart"></Product>
3+
<!--<Product :premium="premium" @add-to-cart="updateCart"></Product>-->
4+
<ProductLine v-for="k in products" :key="k.name" :product="k"></ProductLine>
45

56
<div class="cart">
67
{{ cart.length }}
@@ -12,16 +13,31 @@
1213
<script lang="ts">
1314
import { Component, Vue } from "vue-property-decorator";
1415
import Product from "../components/Product.vue";
16+
import ProductLine from "../components/ProductLine.vue";
17+
import { ProductModel } from '../models';
1518
1619
@Component({
1720
components: {
18-
Product
21+
Product,
22+
ProductLine
1923
}
2024
})
2125
export default class Home extends Vue {
26+
27+
products: ProductModel[] = [];
2228
premium = true;
2329
cart: string[] = [];
2430
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);
39+
}
40+
2541
updateCart(product: any) {
2642
console.log("Adding to cart:", product);
2743
this.cart.push(product);

0 commit comments

Comments
 (0)