参考文档:
https://www.jb51.net/article/161713.htm 或者// 防抖 const debounce = (func, wait, immediate) => { let timeOut; return function () { const context = this; const args = arguments; if (timeOut) { clearTimeout(timeOut); } if (immediate) { let callNow = !timeOut; timeOut = setTimeout(() => { timeOut = null; }, wait || 500) if (callNow) { func.apply(context, args); } } else { timeOut = setTimeout(() => { func.apply(context, args); }, wait || 500); } } }
// 组件中调用 <el-input type='text' @input="test($event)"> // 引入防抖 import {Debounce} from './utils'; export default { methods:{ test(e){ Debounce(()=>{ console.log(e); },1000) } } }