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

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