i watch nested object. but data property undefined.
const app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!',
item: {
foo: 'test',
},
},
//for test run, wait 3000ms
mounted(){
setTimeout(function(){
this.item.foo = 'a';
}.bind(this),3000);
},
watch: {
'item.foo': (newVal, oldVal) => {
console.log(newVal); // running
this.message='new Hello'; // but this.message undefined
},
},
});
arrow functionin Vue instance, create a function using function declaration instead.