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) {}
}

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐