示例:
監聽一下對象 formCode 中 屬性 application 的變化:
<script>
export default{
data(){
return{
formCode:{
application:"",
oldcode:"",
newcode:""
}
}
}
}
</script>
第一種方式:watch 結合 computed
computed:{
application(){
return this.formCode.application
}
},
watch:{
application:function(val){
console.log(val)
}
}
第二種方式: 使用 deep
watch:{
formCode:{
handler(newVal){
console.log(newVal)
},
deep:true
}
}
第三種方式:
watch:{
'formCode.application'(newVal,oldVal){
if(newVal != oldVal && newVal != ""){
this.vDisable = false;
var appName = newVal.split("-")[0]
this.getVersionData(appName)
}
}
}

