vue-gyc-ui
Version:
``` npm i element-ui npm i vue-gyc-ui ```
27 lines (25 loc) • 601 B
JavaScript
//防抖
let timer_debounce = null
export const debounce = function (func, wait) {
if (timer_debounce) {
clearTimeout(timer_debounce)
timer_debounce = null;
}
timer_debounce = setTimeout(() => {
func.apply(this, arguments)
}, wait)
}
//节流
let timer_throttle = null
export const throttle = function (func, wait) {
if (!timer_throttle) {
timer_throttle = setTimeout(() => {
func.apply(this, arguments)
timer_throttle = null;
}, wait)
}
}
export default {
throttle,
debounce
}