可以通過(guò)向 axios
傳遞相關(guān)配置來(lái)創(chuàng)建請(qǐng)求:
// 發(fā)送 POST 請(qǐng)求
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
})
// 獲取遠(yuǎn)端圖片
axios({
method: 'get',
url: 'http://bit.ly/2mTM3nY',
responseType: 'stream'
})
.then(function(response){
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'));
})
// 發(fā)送 GET 請(qǐng)求(默認(rèn)的方法)
axios('/user/12345');
為方便起見,為所有支持的請(qǐng)求方法提供了別名
注意:在使用別名方法時(shí), url
、method
、data
這些屬性都不必在配置中指定。
處理并發(fā)請(qǐng)求的助手函數(shù):
可以使用自定義配置創(chuàng)建一個(gè) axios 實(shí)例
axios.create([config])
const instance = axios.create({
baseURL: 'https://some-domain.com/api/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
})
更多建議: