1.防抖机制
export function throttle(fn, delay = 1000) {
let last = 0; // 上次执行的时间戳
return function(...args) {
const now = Date.now();
if (now - last >= delay) { // 距离上次执行已超过 delay
last = now;
fn.apply(this, args);
}
};
}
2.组件注册使用:
import { throttle } from '@/common/http/functions.js'
methods: {
selectSku:throttle(function (ss : any) {}
}