Skip to content

Commit 56c8510

Browse files
committed
Retrieved product with URI template
1 parent 7102fec commit 56c8510

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/ViewProduct.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,25 @@
4343
};
4444
},
4545
created() {
46-
this.product = this.getProduct(this.productId);
46+
this.getProduct(this.productId)
47+
.then(product => this.product = product);
4748
},
4849
beforeRouteUpdate(to, from, next) {
49-
this.product = this.getProduct(to.params.productId);
50+
this.getProduct(to.params.productId)
51+
.then(product => this.product = product);
52+
5053
next();
5154
},
5255
methods: {
5356
getProduct(productId) {
54-
57+
return this.$http.get('http://localhost:3000/products/{productId}', {
58+
params: {
59+
productId: productId
60+
}
61+
}).then(
62+
response => response.json(),
63+
response => alert("Could not retrieve product!")
64+
);
5565
},
5666
goBack() {
5767
this.$router.history.go(-1);

0 commit comments

Comments
 (0)