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>
2

2 Answers 2

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();
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

You forget the deep attribute for watcher

    watch: {
      manager: {
        handler(value){
          if(value) {
            this.validationManager();
          }
        },
        immediate: true,
        deep: true,
      }
    }

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.