You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tanghe-report/report-ui/src/utils/throttle.js

19 lines
426 B
JavaScript

3 years ago
/**
* 函数节流
*/
export function _throttle(fn,delay){
let timer
var delay = delay || 1000; //一秒内触发一次
return function(...args){
const context = this
let canExecute = !timer
if(canExecute){
fn.apply(context,args)
}else{
clearTimeout(timer)
}
timer = setTimeout(() => {
timer = null
}, delay);
}
}