watch监听数据变化
1.最简单的监听
data() {
return {
name: "张三"
}
},
watch: {
name: function (newValue,oldValue) {},
}
2.监听queryParams下的startTime
data() {
return {
queryParams: {
pageNum: 1,
pageSize: 10,
startTime: null,
endTime: null,
},
}
},
watch: {
"queryParams.startTime": {
handler(val) {
this.endNoTime = {
disabledDate(time) {
const time1 = new Date(val).getTime() - 8.64e7;
return time.getTime() < time1 || time.getTime() > Date.now()
}
}
}
},
3.监听所有queryParams数据的变化 需要给定一个 deep:true
watch: {
queryParams: {
deep:true
handler:function (newValue,oldValue) {
}
},
}