vue watch object code example
Example 1: vue watch deep property
watch: {
item: {
handler(val){
},
deep: true
}
}
Example 2: vue change deep element
Vue.set(vm.someObject, 'b', 2)
Vue.set(vm.items, indexOfItem, newValue)
Example 3: vue watch child property
...
watch:{
'item.someOtherProp'(newVal){
},
'item.prop'(newVal){
}
}
Example 4: vue watch props
new Vue({
el: '#app',
data: {
text: 'Hello'
},
components: {
'child' : {
template: `<p>{{ myprop }}</p>`,
props: ['myprop'],
watch: {
myprop: function(newVal, oldVal) {
console.log('Prop changed: ', newVal, ' | was: ', oldVal)
}
}
}
}
});
Example 5: vue watch object member
watch: {
item: {
handler(val){
},
deep: true
}
}