//父組件
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相當(dāng)于就是執(zhí)行父組件的this.show,但是子組件中并沒(méi)有show這個(gè)方法,為啥不報(bào)“this.props.del?not?a?function”這個(gè)錯(cuò)誤呢,我看慕課上視頻這里是報(bào)錯(cuò)了的,會(huì)不會(huì)是因?yàn)閞eact版本不同的原因呢
}
}
export?default?TodoItems;
關(guān)于react的一個(gè)報(bào)錯(cuò)問(wèn)題,求大神指點(diǎn)
慕田峪8701529
2018-10-31 12:14:49