mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 15:51:52 +08:00
47 lines
890 B
JavaScript
47 lines
890 B
JavaScript
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'
|
|
});
|
|
} |