File tree Expand file tree Collapse file tree 4 files changed +58
-6
lines changed
Expand file tree Collapse file tree 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 11import Vue from "vue" ;
22import Router from "vue-router" ;
33import Home from "./views/Home.vue" ;
4+ import Product from "./components/Product.vue" ;
45
56Vue . 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"
Original file line number Diff line number Diff line change 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 }}
1213<script lang="ts">
1314import { Component , Vue } from " vue-property-decorator" ;
1415import 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})
2125export 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 );
You can’t perform that action at this time.
0 commit comments