美文网首页
useDisableOnShow

useDisableOnShow

作者: Asuler | 来源:发表于2023-10-24 15:53 被阅读0次
    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;
    
    

    相关文章

      网友评论

          本文标题:useDisableOnShow

          本文链接:https://www.haomeiwen.com/subject/soesidtx.html