闭包对某个功能方法确保只执行一次
//每次只执行一次
const showModulBounce = (() => {
let hasExecuted = false; // 添加标志位判断是否已执行
return () => {
if (!hasExecuted) {
hasExecuted = true;
showModal();
}
};
function showModal() {
uni.showModal({
title: 'xxx',
content: 'xxx',
showCancel: false,
success: (res) => {
if (res.confirm) {
}
// 重置标志位,允许下次立即执行
hasExecuted = false;
}
});
}
})();
您还未登录, 登录 后可进行评论
发表
还没有评论哦,来抢个沙发吧!