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是父组件里的函数,传到子组件,当子组件点击事件时触发这个函数
阿波罗的战车
相关分类