function debounce(func, delay=300) { //func为防快速调用的函数,delay为抖动间隔在多少毫秒之内将忽视(此处默认为300毫秒)
let timer = null;
return function (...args) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
func.apply(this,args);
}, delay);
}
}
// 这个函数可以放入vuex的mutations中,组件内使用时:this.$store.commit("debounce",func,delay);
vue 防抖动函数
最新推荐文章于 2024-07-03 19:18:50 发布