tool.js文件
export function deBounce(func, wait) {
let timeOut = null;
return function (...args) {
clearTimeout(timeOut);//一定要清除定时器
timeOut = setTimeout(() => {
func(...args);
}, wait);
};
}
------------------我是史上最帅的分割线-----------------------------------
调用的时候
import { deBounce} from 'tool'
//使用onChange 做为演示
onChange = deBounce(() => {//格式一定要这么写!!!当然箭头函数 你也可以传方法
//此处放置需要防抖的功能
},2000);