» Use immediate: true option in the code indicates that the watcher should be triggered immediately when the component is created, rather than waiting for a change in the watched property.
watch: {
'$route.path': {
immediate: true,
handler(newRoutePath) {
// TODO
},
},
},
» Without immediate: true, the watcher would not be triggered immediately when the component is created. Instead, it would only start watching for changes in the $route.path after the component is created.
computed: {
routePath() {
return this.$route.path;
},
},
watch: {
routePath(newRoutePath) {
if ($('#switchLoginModal').hasClass('myClass')) {
$('#login-modal').removeClass('show');
}
},
}