[中文文檔](http://www.hmoore.net/yunye/axios/234845)
作用相當于jquery中的ajax
用于網絡請求
~~~
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
~~~
可以通過向`axios`傳遞相關配置來創建請求
##### **axios(config)**
##### **axios(url?querystring [, config])**
`axios().then().catch()`
`axios().then(function(response){}).catch(function(err){})`
~~~
// 發送 POST 請求
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
// 發送 POST 請求
axios('/user/12345', {
method: 'post',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
// 發送 GET 請求(默認的方法)
axios('/user/12345');
~~~
### **請求方法的別名**
##### axios.request(config)
##### axios.get(url\[, config\])
##### axios.delete(url\[, config\])
##### axios.head(url\[, config\])
##### axios.post(url\[, data\[, config\]\])
##### axios.put(url\[, data\[, config\]\])
##### axios.patch(url\[, data\[, config\]\])
##### **例子:**
get請求
`axios.get(url?queryString).then(function(response){}).catch(function(err){})`
~~~
// 為給定 ID 的 user 創建請求
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
// 可選地,上面的請求可以這樣做
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
~~~
post請求
`axios.post(url, {key1:value1,key2.value2}).then(function(response){}).catch(function(err){})`
~~~
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
~~~