watch object prop vue code example
Example 1: vue watch props
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)
}
}
}
}
});
Example 2: vue watch object member
// Use a deep watcher for that:
watch: {
item: {
handler(val){
// do stuff
},
deep: true
}
}