vue 如何监听事件动态传至给子组件
1个回答
2018-06-08 · 百度知道合伙人官方认证企业
关注
展开全部
点击后defaultEducation的值明明改变了,但props传给子组件却watch不到
父组件
<choice :text="checkdata" ref="choice" @getchoice="onChoice" @cancel="showToggleCancel" :checkedValue="defaultEducation"></choice>computed: {
geitfasa () { document.addEventListener('tap', function (event) { var focusTargetDom = event.target if (focusTargetDom.tagName.toLowerCase() === 'input' && focusTargetDom.getAttribute('name') === 'checkdata') { this.defaultEducation = focusTargetDom.value console.log(this.defaultEducation)
}
}, true)
}
}
子组件
<input type="radio" :value="item.id" :id="`checkbox_${index}`" :name="item.radioName" v-model="checkedVal" @tap.stop="hideCheck"/>
<label :for="`checkbox_${index}`" :id="`check_${index}`">
{{item.name}}
</label>
props: {
text: {
type: Array, default: []
},
checkedValue: {
type: String, default: ''
}
}, data () { return {
checkedVal: ''
}
},
created () { this.checkedVal = this.checkedValue this.$watch('checkedValue', (newquery) => {
console.log(newquery)
})
}
父组件
<choice :text="checkdata" ref="choice" @getchoice="onChoice" @cancel="showToggleCancel" :checkedValue="defaultEducation"></choice>computed: {
geitfasa () { document.addEventListener('tap', function (event) { var focusTargetDom = event.target if (focusTargetDom.tagName.toLowerCase() === 'input' && focusTargetDom.getAttribute('name') === 'checkdata') { this.defaultEducation = focusTargetDom.value console.log(this.defaultEducation)
}
}, true)
}
}
子组件
<input type="radio" :value="item.id" :id="`checkbox_${index}`" :name="item.radioName" v-model="checkedVal" @tap.stop="hideCheck"/>
<label :for="`checkbox_${index}`" :id="`check_${index}`">
{{item.name}}
</label>
props: {
text: {
type: Array, default: []
},
checkedValue: {
type: String, default: ''
}
}, data () { return {
checkedVal: ''
}
},
created () { this.checkedVal = this.checkedValue this.$watch('checkedValue', (newquery) => {
console.log(newquery)
})
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询