el-input+vue+ts防抖处理
<el-input @input="debounce()" ></el-input>
private timer: any = '';
private debounce(data?: any) {
const _this: any = this;
if (this.timer) {
clearTimeout(this.timer)
}
this.timer = setTimeout(function() {
_this.timer = undefined;
}, 1000);
}
<div @click="throttle()" >点击点击</div>
private timer: any = ''
private lastTime: any = ''
private throttle() {
const _this: any = this;
let now = +new Date()
if (this.lastTime && this.lastTime - now < 2000) {
clearTimeout(this.timer)
}
this.timer = setTimeout(function() {
console.log('点击')
_this.lastTime = +new Date()
}, 200)
}