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>

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

原文地址:https://www.cnblogs.com/cazj/p/11555302.html