<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Axios > 原文:[https://docs.gitlab.com/ee/development/fe_guide/axios.html](https://docs.gitlab.com/ee/development/fe_guide/axios.html) * [CSRF token](#csrf-token) * [Usage](#usage) * [Mock Axios response in tests](#mock-axios-response-in-tests) * [Example](#example) * [Mock poll requests in tests with Axios](#mock-poll-requests-in-tests-with-axios) # Axios[](#axios "Permalink") 我們使用[Axios](https://github.com/axios/axios)在 Vue 應用程序和大多數新代碼中與服務器進行通信. 為了確保設置了所有默認值,您不應*直接使用 Axios* ,而應從`axios_utils`導入 Axios. ## CSRF token[](#csrf-token "Permalink") 我們所有的請求都需要 CSRF 令牌. 為了確保設置此令牌,我們將導入[Axios](https://github.com/axios/axios) ,設置令牌并導出`axios` . 應該使用此導出模塊,而不是直接使用 Axios 以確保已設置令牌. ## Usage[](#usage "Permalink") ``` import axios from './lib/utils/axios_utils'; axios.get(url) .then((response) => { // `data` is the response that was provided by the server const data = response.data; // `headers` the headers that the server responded with // All header names are lower cased const paginationData = response.headers; }) .catch(() => { //handle the error }); ``` ## Mock Axios response in tests[](#mock-axios-response-in-tests "Permalink") 為了幫助我們模擬響應,我們使用[axios-mock-adapter](https://github.com/ctimmerm/axios-mock-adapter) . 比[`spyOn()`](https://jasmine.github.io/api/edge/global.html#spyOn)優勢: * 無需創建響應對象 * 不允許通話(我們要避免) * 簡單的 API 來測試錯誤情況 * 提供`replyOnce()`以允許不同的響應 我們還決定不使用[Axios 攔截器,](https://github.com/axios/axios#interceptors)因為它們不適合模擬. ### Example[](#example "Permalink") ``` import axios from '~/lib/utils/axios_utils'; import MockAdapter from 'axios-mock-adapter'; let mock; beforeEach(() => { // This sets the mock adapter on the default instance mock = new MockAdapter(axios); // Mock any GET request to /users // arguments for reply are (status, data, headers) mock.onGet('/users').reply(200, { users: [ { id: 1, name: 'John Smith' } ] }); }); afterEach(() => { mock.restore(); }); ``` ### Mock poll requests in tests with Axios[](#mock-poll-requests-in-tests-with-axios "Permalink") 因為輪詢功能需要一個標頭對象,所以我們需要始終包含一個對象作為第三個參數: ``` mock.onGet('/users').reply(200, { foo: 'bar' }, {}); ```
                  <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>

                              哎呀哎呀视频在线观看