Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 5fbdf71

Browse files
committed
feat(picker): move 防抖
1 parent cf713cd commit 5fbdf71

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

miniprogram_dist/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { array_move } from 'polyfill.js';
2+
import { throttle } from './polyfill';
23
/**
34
* 临时数据缓存
45
*/
@@ -82,6 +83,10 @@ Component({
8283
return { value: this._getCache().imgs }
8384
},
8485

86+
created(){
87+
this.onChange = throttle(this.onChange);
88+
},
89+
8590
/**
8691
* 初始化缓存
8792
* 渲染全部图标

miniprogram_dist/polyfill.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,19 @@ export function array_move(arr, oldIndex, newIndex) {
2121
arr.splice(newIndex, 0, arr.splice(oldIndex, 1)[0]);
2222
return arr;
2323
};
24+
25+
/**
26+
* 事件节流(防抖)
27+
* @param {Function} func 事件
28+
* @param {number} wait 等待时间ms
29+
*/
30+
export function throttle(func, wait) {
31+
if (!wait) { wait = 300; }
32+
var last = -wait;
33+
return function (event) {
34+
if (event.timeStamp - last > wait) {
35+
func.apply(this, arguments);
36+
last = event.timeStamp;
37+
}
38+
};
39+
}

0 commit comments

Comments
 (0)