watch:{ obj:{ //监听的对象 deep:true, //深度监听设置为 true handler:function(newV,oldV){ console.log(‘watch中:‘,newV) } } }
例如:
data () { return { obj:{ name:‘夜空中最亮的星星‘, age:18 } } }, watch:{ ‘obj.name‘:{ deep:true, handler:function(newV,oldV){ console.log(‘watch中:‘,newV) } } }
data () { return { obj:{ name:‘夜空中最亮的星星‘, age:18 } } }, computed:{ name(){ return this.obj.name; } }, watch:{ name(newV){ console.log(‘watch中name为:‘,newV) } }
原文:https://www.cnblogs.com/C-target/p/14651570.html