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