user12763413
user12763413

Reputation: 1349

watcher in vuejs not working for props value

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>

Upvotes: 0

Views: 1766

Answers (2)

DengSihan
DengSihan

Reputation: 3007

You forget the deep attribute for watcher

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

Upvotes: 1

LastM4N
LastM4N

Reputation: 2240

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();
    }
  }
}

Upvotes: 1

Related Questions