vue中防抖函数的写法以及用法
1.准备好防抖函数 function debounce(func, wait) { let timeout; return function (...args) { if (timeout) clearTimeout(timeout); let isTime = !timeout; timeout = setTimeout(function () { timeout = null; }, wait); if (isTime) func.apply(this, args); }; } 2.html节点 <input type="button" @click="toDoSth" /> 3.methods中调用 methods: { toDoSth: debounce( function () { this.log(); }, 500, true ), log() { console.log(12313); } },