Blame view

report-ui/src/utils/throttle.js 426 Bytes
王涛 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/**
 * 函数节流
 */
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);
    }
}