debounced.js 324 B

1234567891011121314
  1. // 防抖函数
  2. export const debounce = (fn,delay = 100) => {
  3. let valid = true;
  4. return function(...args) {
  5. if(!valid) {
  6. return
  7. }
  8. valid = false;
  9. fn.apply(this,args)
  10. setTimeout(() => {
  11. valid = true
  12. },delay)
  13. }
  14. }