节流,高频事件触发,一定时间内只要执行一次,节流可以减少不断执行频率
-
private timer:any = null;
-
if (this.timer) {
-
clearTimeout(this.timer)
-
}
-
this.timer = setTimeout(() => {
-
// 执行需要节流的函数
-
},400 )
private timer:any = null;
if (this.timer) {
clearTimeout(this.timer)
}
this.timer = setTimeout(() => {
// 执行需要节流的函数
},400 )