美文网首页
2020-12-26 vue input事件防抖与节流

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

作者: jinya2437 | 来源:发表于2020-12-26 11:15 被阅读0次

    每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>

    相关文章

      网友评论

          本文标题:2020-12-26 vue input事件防抖与节流

          本文链接:https://www.haomeiwen.com/subject/zczwnktx.html