vue关于防抖的封装

vue关于防抖的封装

// 防抖 防止表单重复提交
export const Debounce = (fn, t) => {
  let delay = t || 300
  let timer
  return function () {
    let args = arguments;
    if (timer) {
      clearTimeout(timer)
    }

    let callNow = !timer

    timer = setTimeout(() => {
      timer = null
    }, delay)

    if (callNow) fn.apply(this, args)
  }
}

关于使用(举一个列子)


```javascript
download(方法名): Debounce(function() {
    (代码片段)
    }, 1000)

你可能感兴趣的:(防抖的封装)