子组件
_showMessage = (message) => {
this.props.showMessage(message);
}
父组件
_handleClick(){
this.setState({
count:++this.state.count
})
this._dialogsMessage._showMessage("当前计数"+this.state.count);
}
render(){
return(
<div>
this is home~........
<br/>
当前计数{this.state.count}
<br/>
<button onClick={()=>this._handleClick()}>自增</button>
<DialogsMessage ref = {dialogsMessage => this._dialogsMessage = dialogsMessage}/>
</div>
);
}
使用后 后台报错
Uncaught TypeError: this._dialogsMessage._showMessage is not a function