1.监测对象
监听对象的改变时,此时就需要设置deep为true,开启深度监听。 对象中多个属性的话需要 ‘object.key’, 只有一个属性的话直接写对象名称就可以 immediate: true 代表立即执行, 不设置immediate只有当监听到的值发生改变才会触发watch,
loginfor: {
loginName: "",
smsCode: "",
},
watch: {
"loginfor.loginName": {
handler(newName, oldName) {
if (newName.length == 11) {
this.disabled = false;
} else {
this.disabled = true;
}
},
immediate: true,
deep: true,
},
},
2.监测属性,数组都是同样的效果
loginName: "",
watch: {
loginName: {
handler(newName, oldName) {
if (newName.length == 11) {
this.disabled = false;
} else {
this.disabled = true;
}
},
immediate: true,
},
},
|