防抖调不出呀,有熟悉debounce或者闭包的帮看一下吗?
网上弄了个debounce,配上之后完全不起作用,还是重复提交
debounce(func, wait) {
let timer;
return function() {
let context = this;
let args = arguments;
if (timer) clearTimeout(timer);
let callNow = !timer;
timer = setTimeout(() => {
timer = null;
}, wait)
if (callNow) func.apply(context, args);
}
},
//事件函数
submitForm(e) {
this.debounce(this.submit, 1000)(e)
},
submit(e) {
//这里还是重复执行呀
}
代码片段:https://developers.weixin.qq.com/s/OWSCFUmP7njf
debounce的网上参考文档:https://www.cnblogs.com/cc-freiheit/p/10827372.html