节流
封装在js文件抛出(在需要的文件引入此js文件)
function throttle(fn,gapTime) {
if (gapTime == null || gapTime == undefined) {
gapTime = 1500
}
let _lastTime = null
return function () {
let _nowTime = + new Date()
if (_nowTime - _lastTime > gapTime || !_lastTime) {
// 将this和参数传给原函数
fn.apply(this,arguments)
_lastTime = _nowTime
}
}
}
export default throttle