## 創建 axios 實例
創建一個使用默認配置的 axios 實例:
~~~js
const instance = axios.create()
~~~
創建一個使用自定義配置的 axios 實例:
~~~js
const instance = axios.create(config)
~~~
## config 常用配置項
~~~js
{
// 請求 URL
url: '/user',
// 請求 method,默認 get
method: 'get',
// baseURL 會拼接到 url 前面
baseURL: 'https://some-domain.com/api/',
// 請求頭
headers: {'X-Requested-With': 'XMLHttpRequest'},
// 放在請求 URL 中的請求參數
params: {
ID: 12345
},
// 放在 body 里的請求參數
data: {
firstName: 'Fred'
},
// 超時時間
timeout: 1000,
// 返回數據的類型,可以是 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
responseType: 'json', // default
// 返回數據的編碼
responseEncoding: 'utf8', // default
// 返回數據的最大長度
maxContentLength: 2000,
}
~~~