input vue ts 防抖处理

 
<el-input  @input="debounce()" ></el-input>
 
 
// 防抖处理
private timer: any = ''
private debounce(data?: any) {
    let that = this
    if (this.timer) {
      clearTimeout(this.timer)
    }
    this.timer = setTimeout(function() {
     //写你需要防抖处理的事件
      // console.log('输入')
      that.timer = undefined
    }, 1000)
  }
 
 
 
 
//节流
 
<div  @click="throttle()" >点击点击</div>
 
 
 private timer: any = ''
 private lastTime: any = ''
 private throttle() {
    let that = this
    let now = +new Date()
    if (this.lastTime && this.lastTime - now < 2000) {
      clearTimeout(this.timer)
    }
    this.timer = setTimeout(function() {
      console.log('点击')
      that.lastTime = +new Date()
    }, 200)
  }
 
原文地址:https://www.cnblogs.com/lucy1111/p/14341433.html