公共方法添加
function throttle (fn, gapTime) {
if (gapTime === null || gapTime === undefined) {
gapTime = 2500
}
let _lastTime = null
return function () {
let _nowTime = +new Date()
if (_nowTime - _lastTime > gapTime || !_lastTime) {
fn.apply(this, arguments)
_lastTime = _nowTime
}
}
}
导出
export default {
throttle
}
引入
import Tips from '../../utils/index'
使用
yourEvent: Tips.throttle(function (e) {
// 函数体内容
}, 2500),