mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 02:08:43 +08:00 
			
		
		
		
	uni-app引入使用uView
This commit is contained in:
		
							
								
								
									
										30
									
								
								yudao-ui-app/uni_modules/uview-ui/libs/function/throttle.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								yudao-ui-app/uni_modules/uview-ui/libs/function/throttle.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| let timer; let | ||||
|     flag | ||||
| /** | ||||
|  * 节流原理:在一定时间内,只能触发一次 | ||||
|  * | ||||
|  * @param {Function} func 要执行的回调函数 | ||||
|  * @param {Number} wait 延时的时间 | ||||
|  * @param {Boolean} immediate 是否立即执行 | ||||
|  * @return null | ||||
|  */ | ||||
| function throttle(func, wait = 500, immediate = true) { | ||||
|     if (immediate) { | ||||
|         if (!flag) { | ||||
|             flag = true | ||||
|             // 如果是立即执行,则在wait毫秒内开始时执行 | ||||
|             typeof func === 'function' && func() | ||||
|             timer = setTimeout(() => { | ||||
|                 flag = false | ||||
|             }, wait) | ||||
|         } | ||||
|     } else if (!flag) { | ||||
|         flag = true | ||||
|         // 如果是非立即执行,则在wait毫秒内的结束处执行 | ||||
|         timer = setTimeout(() => { | ||||
|             flag = false | ||||
|             typeof func === 'function' && func() | ||||
|         }, wait) | ||||
|     } | ||||
| } | ||||
| export default throttle | ||||
		Reference in New Issue
	
	Block a user
	 sfmind
					sfmind