## 创建 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,
}
~~~