uniapp 防抖节流避免重复触发提交

uniapp yekong 1116℃

方法

export const Debounce = (fn, wait) => {
    let delay = wait|| 500
    let timer
    return function () {
        let args = arguments;
        if (timer) {
            clearTimeout(timer)
        }

        let callNow = !timer

        timer = setTimeout(() => {
            timer = null
        }, delay)

        if (callNow) fn.apply(this, args)
    }
}

引用

    import {
        Debounce
    } from '@/utils/utils.js'

使用

methods: {
formSubmit: Debounce(function(e) {
                
},1000),
}

参考:uniapp按钮防抖防止重复提交

喜欢 (6)