Vue2.0用 watch 觀察 prop 變化(不觸發)
來源:懂視網
責編:小采
時間:2020-11-27 22:30:45
Vue2.0用 watch 觀察 prop 變化(不觸發)
Vue2.0用 watch 觀察 prop 變化(不觸發):本文介紹了Vue2.0用 watch 觀察 prop 變化(不觸發),分享給大家,具體如下: A 組件: export default { props:{ name:{ type:String } }, data () { return { author: Jinkey } }, mounted:function(){ t
導讀Vue2.0用 watch 觀察 prop 變化(不觸發):本文介紹了Vue2.0用 watch 觀察 prop 變化(不觸發),分享給大家,具體如下: A 組件: export default { props:{ name:{ type:String } }, data () { return { author: Jinkey } }, mounted:function(){ t

本文介紹了Vue2.0用 watch 觀察 prop 變化(不觸發),分享給大家,具體如下:
A 組件:
export default {
props:{
name:{
type:String
}
},
data () {
return {
author: "Jinkey"
}
},
mounted:function(){
this.author = 'lili'
},
watch:{
name:function(){
console.log(this.name);
},
author:function(){
console.log('lili');
}
}
}
author 有監測到變化,并輸出了 lili ; name 由 B 組件傳入,卻沒有監測到,控制臺沒有輸出。
在 B 組件里調用 A 組件,并傳值給 name
<firstcomponent :name="name"></firstcomponent>
import firstcomponent from './component/firstcomponent.vue'
export default {
data () {
return {
msg: 'Hello Vue!',
name:'lili'
}
},
components: { firstcomponent}
}
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
Vue2.0用 watch 觀察 prop 變化(不觸發)
Vue2.0用 watch 觀察 prop 變化(不觸發):本文介紹了Vue2.0用 watch 觀察 prop 變化(不觸發),分享給大家,具體如下: A 組件: export default { props:{ name:{ type:String } }, data () { return { author: Jinkey } }, mounted:function(){ t