<div id="app">
<h4>a的值是{
{numbers.a}}</h4>
<input type="button" value="n++" @click="numbers.a++">
</div>
<script>
const vm = new Vue({
el: "#app",
data: {
numbers : {
a : 0,
b : 0
}
},
watch: { // 监视属性
'numbers' : {
handler(newValue, oldValue) {
console.log("numbers对象里面的a被修改了!", newValue.a, oldValue.a);
},
deep : true
}
}
})
</script>
控制台打印出来的是:
和预期不符合,原因可能是,在变更 (不是替换) 对象或数组时,