avatar
use Vue with watchers Vue

» 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');
    }
  },
}
24
full path in Vue component DOM element click event in Vue JS setup authentication with Vue 2 and Firebase Implement toggle bar in Vue Application using Vuex Integrating Google One Tap with Vue access route parameters in Vue.js
You need to login to do this manipulation!