效果图:
子组件
import React, { Component } from 'react'
class myInfo extends Component {
constructor(props) {
super(props)
this.state = {}
}
componentWillMount() {
this.props.toChild('我是react子组件传给父组件的信息');
}
sendMsg = () => {
this.props.toChild('我是点击后react子组件传给父组件的信息');
}
render() {
return (
<div className="myInfo">
myInfo
<br />
<br />
<button onClick={this.sendMsg}>点击传给父组件</button>
</div>
)
}
}
export default myInfo
父组件
import React, { Component } from 'react'
// 引用子组件 声明的名字 必须大写
import MyInfo from './myInfo'
cl