在写项目的时候遇到了一个问题,就是须要动态监听data中一个对象的属性的变化。遇到了许多坑,在此过程当中也发现了两种解决方案。javascript
data() { return { parent:{ child:1 } }; },
watch:{ 'parent.child':{ deep:true, handler: function(newV, oldV) { console.log(newV); } } }
2、经过computed作中介html
computed:{ newChild(){ return this.parent.child; } }
watch:{ newChild(newV,oldV){ alert(newV) } },