<template>
<div>
{{ i }}
<button @click="i++">+</button>
<div>
{{ stu.age }}
<button @click="addage">+</button>
</div>
<hr>
<button @click="add2">数组+</button>
<button @click="stu.a.b.c++">++</button>
</div>
</template>
<script>
export default {
data() {
return {
i: 0,
stu: {
name: "bob",
age: 0,
a:{
b:{
c:1
}
}
},
list:[
{
a:1
}
]
};
},
watch: {
i(v1, v2) {
console.log(v1, v2);
},
stu: {
handler(obj) {
console.log("stu改变了", obj);
},
deep: true,
},
list:{
handler(obj){
console.log('数组改变了',obj)
},
deep:true
}
},
methods: {
addage() {
this.stu.age++
console.log(this.stu.age)
},
add2(){
this.list[0].a++
console.log(this.list[0].a)
},
},
};
</script>
<style>
</style>