我要在父组件的computed中使用子组件的值,有什么办法吗?
computed: {
addButtonDisabled() {
return this.$refs.queryBox.selectSportsType === _const.ALL_SELECTION
},
报错,Error in render: "TypeError: Cannot read property 'selectSportsType' of undefined"
百度了下
computed: {
addButtonDisabled() {
this.$nextTick(()=>{
return this.$refs.queryBox.selectSportsType === _const.ALL_SELECTION
})
},
这样才可以获取到
可是这样又没办法用computed了,
请问有什么解决办法吗,谢谢
目前的写法,父组件声明要用的值addButtonDisabled传给子组件,子组件内修改,下部分为子组件代码
computed: {
addButtonDisabledProp(){
return this.selectSportsType === _const.ALL_SELECTION || this.selectParticipantType === _const.ALL_SELECTION
}
},
watch:{
addButtonDisabledProp(){
this.$emit('update:addButtonDisabled', this.addButtonDisabledProp)
}
},
holdtom
相关分类