父组件
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()
this.state = {
mess:"我是父组件",
}
}
return (
<div>
<Child msg = {this.state.mess} />
</div>
)
子组件
import React from 'react'
export default class Header extends React.Component{
constructor(props){
super(props)
}
render(){
console.log(this.props.msg)//通过 this.props.msg接受
return (
<div className="header">
<h5>子组件:{this.props.msg}</h5>
</div>
)
}
}