防抖方法:
const debounceEvent = ((func, wait = 2000) => {
let timer;
return function (...args) {
if (timer) clearTimeout(timer);
let callNow = !timer;
timer = setTimeout(() => {
timer = null;
}, wait)
if (callNow) func.apply(this, args)
}
});
调用:
const methods = {
clickEvent: debounceEvent((type: any) => {
methods.clickEventFn(type);
})
)