32 lines
642 B
JavaScript
32 lines
642 B
JavaScript
// 处理多次点击
|
|
function throttle(fn, params) {
|
|
// console.log(fn)
|
|
let that = this;
|
|
if (that.onoff === undefined) {
|
|
that.onoff = true;
|
|
}
|
|
if (that.onoff && fn) {
|
|
that.onoff = false;
|
|
if (params) {
|
|
fn(params);
|
|
} else {
|
|
fn()
|
|
}
|
|
this.timer = setTimeout(function () {
|
|
that.onoff = true;
|
|
}, 3000)
|
|
} else {
|
|
!this.timer || clearTimeout(this.timer)
|
|
this.timer = setTimeout(function () {
|
|
that.onoff = true;
|
|
}, 3000);
|
|
uni.showToast({
|
|
title: '请稍后点击',
|
|
icon: 'none',
|
|
duration: 1500
|
|
})
|
|
}
|
|
}
|
|
export {
|
|
throttle
|
|
} |