函数封装
export const debounce = (func, delay) => { let timer = null return function (...args) { if (timer) clearTimeout(timer) timer = setTimeout(() => { func.apply(this, args) }, delay); } }
函数使用
import { debounce } from './utils/common' methods: { input() { debounce(this.test(), 1000) }, test() { console.log('debounce ') } }
标签:防抖,函数,debounce,timer,delay,test From: https://www.cnblogs.com/JC30705/p/16850874.html