1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- let _debounceTimeout = null,
- _throttleRunning = false
-
- /**
- * 防抖
- * 参考文章 https://juejin.cn/post/6844903669389885453
- *
- * @param {Function} 执行函数
- * @param {Number} delay 延时ms
- */
- export const debounce = (fn, delay=500) => {
- clearTimeout(_debounceTimeout);
- _debounceTimeout = setTimeout(() => {
- fn();
- }, delay);
- }
- /**
- * 节流
- * 参考文章 https://juejin.cn/post/6844903669389885453
- *
- * @param {Function} 执行函数
- * @param {Number} delay 延时ms
- */
- export const throttle = (fn, delay=500) => {
- if(_throttleRunning){
- return;
- }
- _throttleRunning = true;
- fn();
- setTimeout(() => {
- _throttleRunning = false;
- }, delay);
- }
- /**
- * toast
- */
- export const msg = (title = '', param={}) => {
- if(!title) return;
- uni.showToast({
- title,
- duration: param.duration || 1500,
- mask: param.mask || false,
- icon: param.icon || 'none'
- });
- }
|