2020-12-26 vue input事件防抖与节流

2020-12-26  本文已影响0人  jinya2437

每0.5s请求一次服务器

<el-input placeholder="请输入教师姓名..." v-model="input" clearable  @input="searchFn">
</el-input>
<script>
 //可以放入项目中的公共方法中进行调用
function debounce(func, wait=500){
    let timeout;
    return function(event){
      clearTimeout(timeout)
      timeout = setTimeout(()=>{
        func.call(this, event)
      },wait)
    }
}
export default{
  methods:{
    searchFn:debounce(function(e){
        this.getTeacherList()
        this.addKeyword(this.input)
        this.refreshKeyword()
   }),
   showFn(){
     console.log("222")
   }
  }
}
</script>
上一篇下一篇

猜你喜欢

热点阅读