//父組件
import?React,{Component,Fragment}?from?'react';
import?TodoItems?from?'./TodoItems'
????class?Todolist?extends?Component?{
????????render(){
????????return(
????????<Fragment><TodoItems?del={this.show}/></Fragment>
????????)
????????}
????????show(){
????????????alert(1)
????????????}
}
export?default?Todolist;
//子組件
import?React,{?Component?}?from?'react';
class?TodoItems?extends?Component{
????constructor(props){
????super(props)
????this.handleDel?=?this.handleDel.bind(this)
}
render(){
????return(
????????<div?onClick={this.handleDel}>1111</div>
????????)
}
handleDel(){
????this.props.del() //這里子組件調(diào)用了父組件的方法,this.props.del相當于就是執(zhí)行父組件的this.show,但是子組件中并沒有show這個方法,為啥不報“this.props.del?not?a?function”這個錯誤呢,我看慕課上視頻這里是報錯了的,會不會是因為react版本不同的原因呢
}
}
export?default?TodoItems;
關(guān)于react的一個報錯問題,求大神指點
慕田峪8701529
2018-10-31 12:14:49