React 防止按钮多次点击事件 重复提交

为了方便,简单的记录一下:

在state中设置一个控制点击事件

this.state = {

isClick: true

}

在点击事件的函数里

handleOk = () => {

const { isClick } = this.state

if (isClick) {   //如果为true 开始执行

this.setState({ isClick: false })   //将isClick 变成false,将不会执行处理事件

// 编写点击事件执行的代码

const that = this   // 为定时器中的setState绑定this

setTimeout(function () {       // 设置延迟事件,1秒后将执行

that.setState({ isClick: true })   // 将isClick设置为true

}, 1000);

}

};

-------------------------------------------------------------------------------------------------------------------------------------------------------------------如遇到问题:+WX:WAZJ-0508,及时联系---------------------------------------------------------------------------------------------------------------------------------------------------

发布了58 篇原创文章 · 获赞 41 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/Zeng__Yi/article/details/88658689