本文介紹了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}}以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答