美文网首页
async...await使用

async...await使用

作者: 不退则进_笑 | 来源:发表于2024-01-07 10:40 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
      </head>
      <body> </body>
      <script>
        const func1 = async () => {
          try {
            const res = await window.fetch(
              'https://test.wistore.net/ovopark-organize/enterprise/getMyInfo',
            );
            console.log(res);
            console.log(11111);
            const data = func2();
            console.log(3333);
          } catch (error) {
            console.log(error);
          }
        };
    
        const func2 = () => {
          console.log(222);
          window.fetch('https://test.wistore.net/ovopark-organize/enterprise/getMyInfo').then((res) => {
            console.log(res);
          });
        };
        func1();
      </script>
    </html>
    

    结果:


    截屏2024-01-08 上午10.39.35.png

    相关文章

      网友评论

          本文标题:async...await使用

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