react 父组件给子组件传值


父组件

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>
)
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM