Vue中实现一个防抖函数

/**

  • 函数防抖
    */
    export function debounce(fn, delay) {
    // 记录上一次的延时器
    var timer = null;
    var delay = delay || 200;
    return function () {
    var args = arguments;
    var that = this;
    // 清除上一次延时器
    clearTimeout(timer)
    timer = setTimeout(function () {
    fn.apply(that, args)
    }, delay);
    }
    }

在Vue文件中通过import引入

posted @ 2020-12-10 12:03  H191413  阅读(206)  评论(0)    收藏  举报