<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] ### 1. 介紹 ~~~ 是可以以同步的方式處理異步 ~~~ ### 2.使用 promise ~~~ <script> const promise = new Promise((resolve,reject)=>{ console.log(1); // resolve(2); reject(3) }) promise.then(res=>{ console.log(res); },err=>{ console.log(err); }) console.log(4); </script> ~~~ ### 3. promise then ~~~ function getData(url){ const promise = new Promise((resolve, reject) => { $.ajax({ url, dataType: "jsonp", success: res => { resolve(res) }, error:err=>{ reject(err); } }) }) return promise; } getData("https://api.douban.com/v2/book/search?q=javascript&count=1").then(res=>{ let id = res.books[0].id; return getData(`https://douban.uieee.com/v2/book/${id}`) }).then(res=>{ console.log(res); }) ~~~ ### 4. promise all ~~~ <script> var url = "https://douban.uieee.com/v2/book/2567698"; var url2 = "http://api.douban.com/v2/movie/in_theaters"; var book = $.ajax({url,dataType:"jsonp"}); var movie = $.ajax({url:url2,dataType:"jsonp"}); Promise.all([book,movie]).then(res=>{ let [book,movie]=res; console.log(book); console.log(movie); handledata(book); handledata(movie); }) function handledata(type){ var subjects=type.subjects; var title=type.title; var movies=[] subjects.forEach(ele => { var temp={ imgUrl:ele.images.small } movies.push(temp); }); var readyData={}; readyData[type]={ movies, title, type }; this.setData(readyData); //console.log(type) } </script> ~~~ 5. async 關鍵字 聲明的函數 調用返回的是個promise對象 ~~~ <script> var url= "http://api.douban.com/v2/movie/in_theaters" async function promise(url) { return $.ajax({url,dataType:"jsonp"}) } async function getData(){ //await等后面的函數執行完成后再執行相應代碼 var data =await promise(url); console.log(data); } getData(); </script> ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看