在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 })