watch:{
isHot:{
immediate:true,//初始化时让handler调用
//handler当isHot改变时调用
handler(newValue,oldValue){
}
}
}
1.当监视的属性变化时,回调函数自动调用,进行相关操作
2.监视的属性必须存在
3.监视的两种写法
3.1new Vue
3.2this.$watch
深度监视
watch:{
isHot:{
//监听多级结构中某个属性得变化
'number.a':{
handler(){
}
}
}
//监视多级
isHot:{
deep:true,
number:{
handler(){
}
}
}
}
1)vue中得watch 默认不检测对象内部值得改变
2)配置deep:true可以检测对象内部值改变
备注:
1)vue自身可以监测对象内部值得改变
2)使用watch时根据数据得具体结构,决定是否采用深度监视
简写
watch:{
isHot(newValue,oldValue){
}
}