I have a component with some items and those items are loaded from api using get request
method. When I click on an item I get redirected to its own page using dynamic routing: { path: '/:id', component: Item }
. Clicked item is recognised using currentItem()
method: currentItem() { this.items.find(item => item.code === this.$route.params.id) }
where item.code
is a property I get from api.
My problem is that when I refresh the page with current item, it is not loaded anymore. I tried using beforeCreate()
to load items one more time in their own component. Maybe I could use a watch
to change the state depending on the item?
beforeCreate() {
this.$http.get(url).then(response => {
this.items = response.body;
}
},
watch: {
'$route' (to, from) {
this.currentItem()
}
}
Here's a demo.