fe-notes
fe-notes copied to clipboard
立即执行防抖函数
function debounce(func, wait) {
let timer = null
let flag = true
return function () {
clearTimeout(timer)
if (flag) {
func.apply(this, arguments)
flag = false
}
timer = setTimeout(() => { flag = true }, wait)
}
}
在 vue 里使用:
methods: {
toPurchaseNow: debounce(async function () {
// do something
}, 1000)
}