const getCurrentPage = () => {
const pages = Taro.getCurrentPages();
const currentPage = pages[pages.length - 1];
return currentPage;
};
// 在fn执行期间,禁用当前页面的onShow
const useDisableOnShow = (fn) => {
return async (...args) => {
const curPage = getCurrentPage();
const onShow = curPage.onShow;
curPage.onShow = () => {};
try {
await fn(...args);
} catch (error) {
} finally {
setTimeout(() => {
curPage.onShow = onShow;
});
}
};
};
export default useDisableOnShow;
网友评论