question
this is the original function throttling method: anonymous function
(Note: return function () {}
cannot be executed in methods
)
excuse me, how can I change it to vue version?
as it is very commonly used in scrolling and Chinese search boxes, please consult
paste code:
created(){
window.addEventListener("scroll", () => {
this.debounce()(this._log, 1000);
}
},
methods: {
debounce (fn, idle) {
let setTm;
console.log("debounce")
if (!idle || idle <= 0) return fn;
return function () {
clearTimeout(setTm);
setTm = setTimeout(fn.bind(this, ...arguments), idle);
}
},
_log(){
console.log("_log")
},
}