react ,写了li的点击事件,从子组件传入父组件,this.props.onChange报错,this.props.onChange is not a function;handleTabClick在初始化时已经绑定了this
handleTabClick(activeIndex){
const prevIndex = this.state.prevIndex;
//如果当前activeIndex 与传入的activeIndex 不一致并且props中存在defaultActiveIndex时则更新
if(this.state.activeIndex !==activeIndex && 'defaultActiveIndex' in this.props){
this.setState({
activeIndex,
prevIndex,
});
// 更新后执行回调函数,抛出当前索引和上一次索引
this.props.onChange({activeIndex,prevIndex});
}
}
这个handleTabClick是父组件里的函数,传到子组件,当子组件点击事件时触发这个函数
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
看不到你父组件怎么写的。父组件有写onChange={this.onchange}??前面的C要大写。
一开始用static声明的这个函数,在props中查不到