3👍
This may be normal, because this component is not destroyed, but the $route
parameters have changed.
So you can watch the $route
for params.category_name
changed
watch: {
// when redirect to new category_name, this will be callback
'$route': (new, old) => {
if (new.params.category_name !== old.params.category_name) {
// reload data, same with created()
}
}
}
see more: https://router.vuejs.org/guide/advanced/data-fetching.html#fetching-after-navigation
- [Vuejs]-How to customize the backgorund-color of cancel-button in b-modal?
- [Vuejs]-Vue show modal click using data from JSON
0👍
I would prefer to use the watch lifecycle in Vue.js.
Basically what is does is watching your route and when it changes you can tell it to run a function.
example:
watch: {
// call again the method if the route changes
'$route': 'initService'
}
- [Vuejs]-How to put normal Javascript into VueJS
- [Vuejs]-How to conditionally apply text to data variable based on props in VueJS
Source:stackexchange.com