加载中...
  • react子组件向父组件传值

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

    父组件

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

    子组件

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

    1
    <Button type={'link'} onClick={this.props.getChildValue.bind(this, 'aaaaa')}>查询</Button>
    上一篇:
    js将手机号中间四位变成*号
    下一篇:
    _tarojs_taro__WEBPACK_IMPORTED_MODULE_1__.default.useState is not a function
    本文目录
    本文目录