react子组件向父组件传值


将父组件的方法传递给子组件,子组件通过this.props调用传递过来的方法,并带上参数

父组件

import TableSelect from './tableSelect'
  // 获取模糊搜索选择的数据
  childValue = (data)=>{
    console.log(data)
  }
// 使用子组件   在父组件中将getChildValue传递给子组件
   <TableSelect getChildValue={this.childValue} />

子组件    调用传递过来的getChildValue方法,并传入this,传递的参数带在后面,此时父组件中的childValue会得到该值

<Button type={'link'} onClick={this.props.getChildValue.bind(this, 'aaaaa')}>查询</Button>

 将子组件的数据组合之后传递

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM