
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} } 1 akaylh OP 测试了下,发现 watch 好像对 String 类型的 prop 无效,但对 Object 类型的 Prop 有效 |
2 sox 2016-11-24 21:45:41 +08:00 name 又没改变怎么会触发 |