防抖函数

function debounce(fn, delay = 300) {   //默认300毫秒
let timer;
return function() {
let args = arguments;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn.apply(this, args); // this 指向vue
}, delay);
};
}
posted @ 2022-04-28 15:16  莣ㄋ噯  阅读(23)  评论(0)    收藏  举报