useDisableOnShow

2023-10-24  本文已影响0人  Asuler
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;

上一篇 下一篇

猜你喜欢

热点阅读