deep选项为true时, 可进行指针的深度监听,不只是对象,数组也是同样会被深度监听
immediate选项为true时,当前监听回调函数会在Vue实例加载时立即触发回调
watch: {
obj: {
handler(newVal, oldVal) {
console.log("newVal ===>>>", newVal);
console.log("oldVal ===>>>", oldVal);
},
deep: true,
immediate: true,
},
},
data() {
return {
obj: {
name: "张三",
sex: "18",
},
};
}