在vue中會使用很多子組件,有時因為組件的類型的等原因會導致數據監聽不到的情況
1、首次監聽不到時 可以使用immediate方法,其值是true或false;immediate:true代表如果在wacth里聲明了之后,就會立即執行里面的handler方法
watch: {
contractFile: {
immediate: true,
handler: function (newval) {
this.operations(newval)
} }},
2、子組件的深度監聽函數【deep】,其值是true或false;確認是否深入監聽。deep的意思就是深入觀察,監聽器會一層層的往下遍歷,給對象的所有屬性都加上這個監聽器(受現代 JavaScript 的限制 (以及廢棄 Object.observe),Vue 不能檢測到對象屬性的添加或刪除)
watch:{
uploadImageUrl:{
deep:true,
handler:function(newval){
this.uploadShowImageUrl = newval;
}
}},
參考鏈接 https://blog.csdn.net/ying940718/article/details/102620807