单个点击时防暴力点击

let timer = null; //定时器
let lastTime = 0; //当前时间戳
let lastTimeState = true; //控制频繁请求时的执行先后
let methods = null;
// menth, 执行数据
// duration,间隔时间
// type,判断点击是否一样
<-- 思路还是来源于节流(写的也有问题没解决,这个只是单个按钮,如果切换应该是针对多对多的时间判断) -->
export function throttle(menth, duration ,type) {
var that = this;
if(methods == type){
var current = new Date().getTime();
if (current - lastTime >= duration) {
lastTime = current;
return menth();
} else {
lastTime = current;
}
}else{
methods = type;
lastTime = new Date().getTime();
return menth();
}
}

posted @ 2021-02-23 18:40  普通不代表懦弱。  阅读(75)  评论(0)    收藏  举报