描述
阻止多次点击插件,本文以react
为例
安装
npm install prevent-multiple-clicks --save-dev
使用
...{ifPreventClick return;console;// setTimeout 模拟调接口;}...<p onClick= {this}>按钮</p>
API
.stop(key)
阻止点击(只有第一次点击事件生效)
- key{string} 一个点击事件唯一的
key
值
.start(key[, delay])
按钮可以点击,用于.stop(key)
解除
- key{string} 一个点击事件唯一的
key
值 - delay{number} 再次点击等待的时间
.getAll()
获取所有的值,可用于loading
.get(key)
获取单个值
.remove(key)
删除单个值
.clearAll(key)
清除所有的值
使用loading
...thisstate =loading: PreventClick;...{ifPreventClick return;this;console;// setTimeout 模拟调接口;}...<p onClick= {this}>按钮</p><span>loading"key" ? "loading" : "加载完了"</span>
使用demo
git close https://github.com/kszitt/prevent-multiple-clicks.gitnpm installnpm start
打开http://localhost:3000
,template/home.js是具体的代码