生活随笔
收集整理的這篇文章主要介紹了
axios 请求的配置选项
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這些是創建請求時可以用的配置選項。只有url是必須的,如果沒有指定method,請求將默認使用get方法。
axiosaxios 最全 請求攔截器 響應攔截器 配置公共請求頭 超時時間 以及get delete post put 四種請求傳參方式可以參考這篇文章
{ url
: '/user', method
: 'get', baseURL
: 'https://some-domain.com/api/', transformRequest
: [function (data
, headers
) { return data
; }], transformResponse
: [function (data
) { return data
; }], headers
: {'X-Requested-With': 'XMLHttpRequest'}, params
: { ID: 12345 }, paramsSerializer
: function (params
) { return QS.stringify(params
, {arrayFormat
: 'brackets'}) }, data
: { firstName
: 'Fred' }, timeout
: 1000, withCredentials
: false, adapter
: function (config
) { }, auth
: { username
: 'janedoe', password
: 's00pers3cret' }, responseType
: 'json', responseEncoding
: 'utf-8', xsrfHeaderName
: 'X-XSRF-TOKEN', onUploadProgress
: function (progressEvent
) { }, onDownloadProgress
: function (progressEvent
) { }, maxContentLength
: 2000, validateStatus
: function (status
) { return status
>= 200 && status
< 300; }, maxRedirects
: 5, ocketPath
: null, httpAgent
: new http.Agent({ keepAlive
: true }), httpsAgent
: new https.Agent({ keepAlive
: true }), proxy
: { host
: '127.0.0.1', port
: 9000, auth
: { username
: 'mikeymike', password
: 'rapunz31' } }, cancelToken
: new CancelToken(function (cancel
) { }) }
總結
以上是生活随笔為你收集整理的axios 请求的配置选项的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。