throttle-debounce使用noTrailing报错callback.apply is not a function——解决

在vue项目中使用 throttle-debounce 插件,需要对按钮做节流处理(多次点击只请求一次,且最后一次不执行),然后用了 throttle,代码如下:

throttle(3000, true, function() {
    
    
 //...
})

因为看到throttle使用介绍是这样的,如下图:
在这里插入图片描述但是这样使用noTrailing报错,callback.apply is not a function
在这里插入图片描述
于是查看报错位置:
在这里插入图片描述
发现其参数格式不是throttle(delay, noTrailing, callback, debounceMode),而是 throttle(delay, callback, options),这个options里面才包含noTrailing和debounceMode。

于是,修改代码如下:

throttle(3000, function() {
    
    
 //...
}, {
    
     noTrailing: true })

猜你喜欢

转载自blog.csdn.net/weixin_42566993/article/details/128092871