//父组件
import DividendModal from "./dividendModal"
class Dividend extends Component {
constructor(props) {
super(props);
//this.dividendModal= React.createRef(); ⑶
}
dividendRecord = (id, name) => {
//第一种ref调用子组件的方法
this.dividendModal.handleVisible() // ⑴
//第二种ref的写法
//this.refs.dividendModal ⑵
//第三种ref对节点的引用可以通过ref的current属性得到
//this.dividendModal.current ⑶
this.dividendModal.props.form.setFieldsValue({
fund: ""
})
}
getInfo = (value) => {
this.setState({
value
})
}
render() {
return (
<>
<DividendModal
{...this.props}
{...this.state}
smallColumns={smallColumns}
rowKey={'nId'}
//回调函数 ⑴
ref={node => this.dividendModal = node}
//字符串形式 ⑵
//ref="dividendModal"
//React.createRef() ⑶
//ref= {this.dividendModal}
handleInfo={this.getInfo}
/>
</>
)
}
}
//子组件
class DividednModal extends Component {
//通过this.props调用父组件的属性和方法
handleVisible = () => {
this.setState({
visible: true
})
//通过props的方法把值传给父组件
this.props.handleInfo("react子组件传值啦!")
}
}