File tree Expand file tree Collapse file tree 4 files changed +59
-2
lines changed
Expand file tree Collapse file tree 4 files changed +59
-2
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" ;
5+
46import Cart from "./views/Cart.vue" ;
57Vue . use ( Router ) ;
68
@@ -21,6 +23,11 @@ export default new Router({
2123 // which is lazy-loaded when the route is visited.
2224 component : ( ) => import ( /* webpackChunkName: "counter" */ "./views/Counter.vue" )
2325 } ,
26+ {
27+ name : 'product' ,
28+ path : '/product/:id' ,
29+ component : Product
30+ } ,
2431 {
2532 path : "/cart" ,
2633 name : "cart" ,
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 :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 >
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