import React from 'react'
import '../page1/header.css'
import { Table } from 'antd'
import Child from './child'//引入的子组件
//父组件
export default class Header extends React.Component{
constructor(){
super()
}
}
handleClick = (val) => { //val就是子组件传的值1
this.setState({
mess:val
})
}
render(){
return (<div>
<Child GETState= {this.handleClick.bind(this)}/>
</div>
)
}
// 子组件
import React from 'react'
export default class Header extends React.Component{
constructor(props){
super(props)
this.state = {
a:1
}
}
render(){
console.log(this.props.msg)
return (
<div className="header">
<div onClick={() =>this.props.GETState(this.state.a)}>给父元素传值</div> //点击就把当前页的值传给父组件
</div>
)
}
}