手写一个防抖的方法

65 阅读1分钟
function debounce(func, delay) {
  let timerId;
 return (...args) => {
  clearTimeout(timerId);
  timerId = setTimeout(() => {
    func(...args);
  }, delay);
};
}
function myFunction() {
  console.log('Debounced function called');
}
const debouncedClick = debounce(myFunction, 1000);

  <button @click="debouncedClick">点击按钮</button>