File tree 4 files changed +58
-6
lines changed
4 files changed +58
-6
lines changed Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
import Vue from "vue" ;
2
2
import Router from "vue-router" ;
3
3
import Home from "./views/Home.vue" ;
4
+ import Product from "./components/Product.vue" ;
4
5
5
6
Vue . use ( Router ) ;
6
7
@@ -21,10 +22,11 @@ export default new Router({
21
22
// which is lazy-loaded when the route is visited.
22
23
component : ( ) => import ( /* webpackChunkName: "counter" */ "./views/Counter.vue" )
23
24
} ,
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
+ }
28
30
// Get id with: {{ $route.params.id }}
29
31
// Example:
30
32
// path: "/user/:username/post/:post_id"
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<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 >
4
5
5
6
<div class =" cart" >
6
7
{{ cart.length }}
12
13
<script lang="ts">
13
14
import { Component , Vue } from " vue-property-decorator" ;
14
15
import Product from " ../components/Product.vue" ;
16
+ import ProductLine from " ../components/ProductLine.vue" ;
17
+ import { ProductModel } from ' ../models' ;
15
18
16
19
@Component ({
17
20
components: {
18
- Product
21
+ Product ,
22
+ ProductLine
19
23
}
20
24
})
21
25
export default class Home extends Vue {
26
+
27
+ products: ProductModel [] = [];
22
28
premium = true ;
23
29
cart: string [] = [];
24
30
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
+
25
41
updateCart(product : any ) {
26
42
console .log (" Adding to cart:" , product );
27
43
this .cart .push (product );
You can’t perform that action at this time.
0 commit comments