您的位置:首页 > Web前端 > Vue.js

Vue2.0用 watch 观察 prop 变化(不触发)

2017-09-08 17:15 741 查看

本文介绍了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}
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vue watch prop