/* 防抖 */
const myDebounce = (fn: () => void, delay: number | undefined) => {
let timer: NodeJS.Timeout;
return function () {
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
fn()
}, delay)
}
};
/* 节流 */
const myThrottle = (fn: () => void, delay: number | undefined)=> {
const isThtottle = ref(true)
return () => {
if (!isThtottle.value) return
isThtottle.value = false
setTimeout(() => {
fn()
isThtottle.value = true
}, delay)
}
};