close

[Solved] How to listen for ‘props’ changes

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error How to listen for ‘props’ changes in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How to listen for ‘props’ changes Error Occurs?

Today I get the following error How to listen for ‘props’ changes in javascript.

How To Solve listen for ‘props’ changes Error ?

  1. How To Solve listen for 'props' changes Error ?

    To Solve listen for 'props' changes Error if myProp is an object, it may not be changed in usual. so, watch will never be triggered. the reason of why myProp not be changed is that you just set some keys of myProp in most cases. the myProp itself is still the one. try to watch props of myProp, like “myProp.a”,it should work.

  2. How to listen for 'props' changes

    To Solve listen for 'props' changes Error if myProp is an object, it may not be changed in usual. so, watch will never be triggered. the reason of why myProp not be changed is that you just set some keys of myProp in most cases. the myProp itself is still the one. try to watch props of myProp, like “myProp.a”,it should work.

Solution 1


for two way binding you have to use .sync modifier

<child :myprop.sync="text"></child>

more details…

and you have to use watch property in child component to listen and update any changes

props: ['myprop'],
  watch: { 
    myprop: function(newVal, oldVal) { // watch it
      console.log('Prop changed: ', newVal, ' | was: ', oldVal)
    }
  }

Solution 2

The watch function should place in Child component. Not parent.

Solution 3

if myProp is an object, it may not be changed in usual. so, watch will never be triggered. the reason of why myProp not be changed is that you just set some keys of myProp in most cases. the myProp itself is still the one. try to watch props of myProp, like “myProp.a”,it should work.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment