vue中的防抖与节流,minxin
参考文档:
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) } } }
Minxin参考地址:https://blog.csdn.net/qq_38128179/article/details/107817436