子级向父级传递"55"(实质是父级向子级传递了一个方法,供子级调用)
import React, { Component } from 'react';
class Ch extends React.Component{
constructor(...args){
super(...args)
this.num=55
}
render(){
this.props.a(this.num)
return <div></div>
}
}
class Fa extends React.Component{
constructor(...args){
super(...args)
}
fn(num){
alert(num)
}
render(){
return <div><Ch a={this.fn.bind(this)}/>
</div>
}
}
export default Fa;