1.新建comm.js

**
 * 函数防抖
 */
export function debounce(fn, delay) {
  // 记录上一次的延时器
  var timer = null;
  var delay = delay || 200;
  return function() {
    var args = arguments;
    var that = this;
    // 清除上一次延时器
    clearTimeout(timer)
    timer = setTimeout(function() {
        fn.apply(that,args)
    }, delay);
  }
}

2.在vue组件中引入

import {debounce} from '@/utils/comm.js'

3.在组件中使用

<div class="white-search-bar">
        <div class="search-bar-item">
          <input  @on-change="appSearch">
</div>
</div>

methods:{
  appSearch:debounce(function(){
  
this.getAppList()
   },
300)
 }

 

posted on 2020-06-10 11:21  鄢宁  阅读(196)  评论(0编辑  收藏  举报