123456789101112131415161718192021 |
- /**
- * 方法节流
- * @param wait 节流时间 单位秒
- */
- export default function Throttle(wait: number) {
- return function (target: any, keyname: string, descriptor: PropertyDescriptor) {
- const method: Function = descriptor.value;
- let timer: number = null;
- descriptor.value = function (...args: any[]) {
- if (timer) {
- return;
- } else {
- timer = setInterval(() => {
- clearInterval(timer);
- timer = null;
- }, wait * 1000);
- return method.apply(this, args);
- }
- };
- };
- }
|