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();
}
}
原文:https://www.cnblogs.com/XieYu07/p/14437569.html