mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Actually added the Async example
Also, added notes about using Async/Await with caution
This commit is contained in:
@@ -74,15 +74,20 @@ axios.get('/user', {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Want to use async/await?
|
// Want to use async/await? Add the `async` keyword to your outer function/method.
|
||||||
|
async function getUser() {
|
||||||
try {
|
try {
|
||||||
const response = axios.get('/user?ID=12345');
|
const response = await axios.get('/user?ID=12345');
|
||||||
console.log(response);
|
console.log(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(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
|
Performing a `POST` request
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user