1234567891011121314151617181920212223242526272829 |
- /**
- * 防止用户多次输入
- * @param cb 来源
- * @param delay 延迟时间
- * @returns {(function(...[*]): void)|*}
- */
- export function debounce(cb, delay) {
- let timer
- return function (...args) {
- if (timer) {
- clearTimeout(timer)
- }
- timer = setTimeout(() => {
- cb.call(this, ...args)
- }, delay)
- }
- }
- export function functionDebounce(cb, delay) {
- let timer
- return function () {
- if (timer) {
- clearTimeout(timer)
- }
- timer = setTimeout(() => {
- cb.call(this)
- }, delay)
- };
- }
|