子组件中watch无法监听到props父组件传递的值
父组件:
<channel ref="channelVideoTalk" :formData="formData"><channel>
this.formData = fromUser
子组件:
props: {
formData: {
type: Object,
default: () => {}
}
},
watch:{
formData: function(newVal,oldVal) {
console.log('&&&&&&&&&&&',newVal,oldVal)
}
},
- 父组件未在data定义formData,导致子组件无法监听;在父组件data中定义formData初始化值即可
父组件添加如下:
data() {
return {
formData: null,
}
},