How to listen for 'props' changes How to listen for 'props' changes vue.js vue.js

How to listen for 'props' changes


You can watch props to execute some code upon props changes:

new Vue({  el: '#app',  data: {    text: 'Hello'  },  components: {    'child' : {      template: `<p>{{ myprop }}</p>`,      props: ['myprop'],      watch: {       	myprop: function(newVal, oldVal) { // watch it          console.log('Prop changed: ', newVal, ' | was: ', oldVal)        }      }    }  }});
<script src="https://unpkg.com/vue/dist/vue.js"></script><div id="app">  <child :myprop="text"></child>  <button @click="text = 'Another text'">Change text</button></div>