聪明的人懂得说,智慧的人懂得听,高明的人懂得问。若要前行,就得离开你现在停留的地方。早安!
本文介绍了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}
}
本文Vue2.0用 watch 观察 prop 变化(不触发)到此结束。当你觉得沮丧失落,能量低迷,别人会觉得不能托付给一个不自信的人。小编再次感谢大家对我们的支持!



