为了账号安全,请及时绑定邮箱和手机立即绑定

我要在父组件的computed中使用子组件的值,有什么办法吗?

我要在父组件的computed中使用子组件的值,有什么办法吗?

慕哥9229398 2018-07-18 08:43:11
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了,请问有什么解决办法吗,谢谢
查看完整描述

2 回答

?
偶然的你

TA贡献1841条经验 获得超3个赞

在父组件的 data中声明你需要用到的值来存储子组件的那个值;
因为组件挂载顺序的问题 父组件data声明的时候子组件的data还没有初始化好;
所以你要在父组件mounted中通过this.$refs.xxxx.xxxx拿到这个值,并赋值给data中的值;
父级的computed 会根据这个data中的值重新计算

查看完整回答
反对 回复 2018-07-18
  • 2 回答
  • 0 关注
  • 1442 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信