Skip to content

Commit 4c4d2e3

Browse files
committed
Added back button and image navigation
1 parent 6250ab6 commit 4c4d2e3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ProductList.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div id="products" class="row list-group">
33
<div v-for="product in products" class="item col-xs-4">
44
<div class="thumbnail">
5-
<img class="group list-group-image" src="http://placehold.it/400x250/000/fff">
5+
<img @click="clickedImage(product)" class="group list-group-image" src="http://placehold.it/400x250/000/fff">
66
<div class="caption">
77
<router-link
88
:to="{ name: 'viewProduct', params: { productId: product.id } }"
@@ -48,6 +48,14 @@
4848
product: product,
4949
quantity: quantity
5050
});
51+
},
52+
clickedImage(product) {
53+
this.$router.push({
54+
name: 'viewProduct',
55+
params: {
56+
productId: product.id
57+
}
58+
});
5159
}
5260
}
5361
}

src/ViewProduct.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<template>
22
<div>
3+
<button class="btn btn-primary" @click="goBack">&laquo; Back</button>
4+
35
<h1>{{ product.name }}</h1>
46
<p><strong>ID:</strong> {{ product.id }}</p>
57
<p><strong>Price:</strong> {{ product.price | currency }}</p>
@@ -53,6 +55,9 @@
5355
});
5456
5557
return match;
58+
},
59+
goBack() {
60+
this.$router.push('/');
5661
}
5762
},
5863
computed: {

0 commit comments

Comments
 (0)