由于某种原因,onSlideClick(回调)在第二次点击时返回了正确的结果……当我用push()替换了传播算子时,它起作用了。为什么此功能仅在第二次单击时才将索引添加到slidesIndex?
handleClick = (index) => {
const { onSlideClick } = this.props
const { slidesIndex } = this.state
if (!slidesIndex.includes(slidesIndex[index])) {
this.setState({
slidesIndex: [...slidesIndex, index]
})
console.log('add')
}
onSlideClick(slidesIndex)
}