0

I am working on vue app. The issue I am facing here is that I want to run a method if props has value and in my case manager value. So I am trying something like this but the debugger is not called in the watcher. Please help me find where I am going wrong.

<script>
  export default {
    props: ['manager'],
    watch: {
      manager: function (value) {
        debugger
        if(value) {
          this.validationManager();
        }
      }
    },
    methods: {
      validationManager(){
        console.log("Hello")
      }
    }
  };
</script>
user12763413
  • 1,177
  • 3
  • 18
  • 53

2 Answers2

1

We can definetely watch the props, please try this:

watch: {
  manager: {
    // the callback will be called immediately after the start of the observation
    immediate: true, 
    handler (val, oldVal) {
      //do your stuff here
      this.validationManager();
    }
  }
}
LastM4N
  • 1,890
  • 1
  • 16
  • 22
1

You forget the deep attribute for watcher

    watch: {
      manager: {
        handler(value){
          if(value) {
            this.validationManager();
          }
        },
        immediate: true,
        deep: true,
      }
    }
DengSihan
  • 2,119
  • 1
  • 13
  • 40
  • If the prop is not a boolean, ```deep: true``` is needed to detect changes. Also, you can try 'forcing' it with `if (val !=== oldVal)` inside of `handler (val, oldVal) { //do your stuff here this.validationManager(); }` following @Stefanos_Apk's answer. @Ntx answer should work. – the_flucs Jan 07 '21 at 11:00