2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

Merge pull request #1276 from dericcain/patch-1

Added a simple async/await example
This commit is contained in:
Emily Morehouse
2018-02-22 20:03:46 -07:00
committed by GitHub
+13
View File
@@ -74,8 +74,21 @@ axios.get('/user', {
.catch(function (error) {
console.log(error);
});
// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {
try {
const response = await axios.get('/user?ID=12345');
console.log(response);
} catch (error) {
console.error(error);
}
}
```
> **NOTE:** `async/await` is part of ECMAScript 2017 and is not supported in Internet
> Explorer and older browsers, so use with caution.
Performing a `POST` request
```js