<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Axios基于 Promise 的 HTTP 客戶端

          聯(lián)合創(chuàng)作 · 2023-09-23 15:19

          Axios,基于 Promise 的 HTTP 客戶端,可以工作于瀏覽器中,也可以在 node.js 中使用。

          功能:

          • 從瀏覽器中創(chuàng)建 XMLHttpRequest

          • 從 node.js 中創(chuàng)建 http 請求

          • 支持 Promise API

          • 攔截請求和響應(yīng)

          • 轉(zhuǎn)換請求和響應(yīng)數(shù)據(jù)

          • 取消請求

          • 自動(dòng)轉(zhuǎn)換 JSON 數(shù)據(jù)

          • 客戶端支持防止 XSRF 攻擊

          示例代碼:

          執(zhí)行一個(gè) GET 請求

          // Make a request for a user with a given ID
          axios.get('/user?ID=12345')
            .then(function (response) {
              console.log(response);
            })
            .catch(function (error) {
              console.log(error);
            });
          // Optionally the request above could also be done as
          axios.get('/user', {
              params: {
                ID: 12345
              }
            })
            .then(function (response) {
              console.log(response);
            })
            .catch(function (error) {
              console.log(error);
            });

          執(zhí)行一個(gè) POST 請求

          axios.post('/user', {
              firstName: 'Fred',
              lastName: 'Flintstone'
            })
            .then(function (response) {
              console.log(response);
            })
            .catch(function (error) {
              console.log(error);
            });

          執(zhí)行多個(gè)并發(fā)請求

          function getUserAccount() {
            return axios.get('/user/12345');
          }
          function getUserPermissions() {
            return axios.get('/user/12345/permissions');
          }
          axios.all([getUserAccount(), getUserPermissions()])
            .then(axios.spread(function (acct, perms) {
              // Both requests are now complete
            }));
          瀏覽 21
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  婷婷激情五月综合 | 中文字幕在线和永久在线的区别 | 奶一区| Huangse视频在线观看免费 | 69精品无码成人久久久久久 |