Skip to content

Commit 9f6af5f

Browse files
committed
Used props instead of object
1 parent c1a0134 commit 9f6af5f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/ViewProduct.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
import { products } from './data/products';
1313
1414
export default {
15+
props: {
16+
productId: {
17+
required: true
18+
}
19+
},
1520
data() {
1621
return {
1722
products: products,
1823
product: null
1924
};
2025
},
2126
created() {
22-
let productId = this.$route.params.productId;
23-
this.product = this.getProduct(productId);
27+
this.product = this.getProduct(this.productId);
2428
},
2529
methods: {
2630
getProduct(productId) {

src/routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import ViewProduct from './ViewProduct.vue';
55
export const routes = [
66
{ path: '', component: ProductList },
77
{ path: '/cart', component: Cart },
8-
{ path: '/products/:productId', name: 'viewProduct', component: ViewProduct },
8+
{ path: '/products/:productId', name: 'viewProduct', props: true, component: ViewProduct },
99
{ path: '*', component: { template: '<h1>Page Not Found!</h1>' } }
1010
];

0 commit comments

Comments
 (0)