借助闭包实现短时间内连续点击多次触发事件
startBluetooth = () => {
// 在2s内连点5次进入页面
let clickCount = 0; // 点击次数
let timeFlag = true; // 是否添加计时
return () => {
clickCount += 1;
if (clickCount >= 5) {
this.setState({ // 这是写筒子们自己的逻辑
isOpened: true
})
}
if (timeFlag) { // 多次点击只触发一次
timeFlag = false;
setTimeout(() => {
clickCount = 0;
timeFlag = true;
}, 2000);
}
}
}
页面调用(这里要注意,不能写成onClick={() => {this.startBluetooth()()} )
<View className='user-info-white-block-title' onClick={this.startBluetooth()} >
点击按钮
</View>