util.js
// 防抖
export const debounce = (fn, interval)=>{
var timer;
var gapTime = interval || 1000;//间隔时间,如果interval不传,则默认1000ms
return function() {
clearTimeout(timer);
var context = this;
var args = arguments;//保存此处的arguments,因为setTimeout是全局的,arguments不是防抖函数需要的。
timer = setTimeout(function() {
fn.call(context,args);
}, gapTime);
};
}
在需要防抖的页面引入
import {
debounce
} from "../../utils/util"
Page({
// 删除审核未通过的
del:debounce(function () {
wx.showLoading({
title: '删除中',
})
fetch.post({
url:api.flatAvatarDelete,
data:{audit_id:this.data.mateInfo.audit_id},
success:(res)=> {
const lastPage = getCurrentPages()[0]
lastPage.needRefresh = true
wx.showToast({
title: '删除成功',
icon: 'success',
duration: 2000
})
wx.navigateBack()
},
fail: (err)=> {
wx.showToast({
title: err.data.message,
icon: 'none',
duration: 2000
})
},
})
}),
})
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/64791.html