【发布时间】:2018-10-02 09:17:41
【问题描述】:
我看嵌套对象。但数据属性未定义。
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
},
},
});
【问题讨论】:
-
避免在 Vue 实例中使用
arrow function,而是使用 function declaration 创建函数。 -
@NguyễnThanhTú,哦,谢谢。我不知道。解决了。