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} }