分离搜索框业务逻辑,优化搜索框搜索体验

This commit is contained in:
lyswhut
2019-10-17 10:58:09 +08:00
parent 45fea5726b
commit 59627e048f
4 changed files with 148 additions and 61 deletions
+18
View File
@@ -305,6 +305,24 @@ export const throttle = (fn, delay = 100) => {
}
}
/**
* 生成防抖函数
* @param {*} fn
* @param {*} delay
*/
export const debounce = (fn, delay = 100) => {
let timer = null
let _args = null
return function(...args) {
_args = args
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
timer = null
fn.apply(this, _args)
}, delay)
}
}
const async_removeItem = (arr, num, callback) => window.requestAnimationFrame(() => {
let len = arr.length
if (len > num) {