feat(async-await): add await in before fetch()
This commit is contained in:
parent
5a66948cb7
commit
93d9cd87a1
|
@ -1,9 +1,9 @@
|
||||||
async function fetchDataFromApi() {
|
async function fetchDataFromApi() {
|
||||||
console.log('fetchDataFromApi() start...');
|
console.log('fetchDataFromApi() start...');
|
||||||
|
|
||||||
fetch('https://v2.jokeapi.dev/joke/Programming?type=single')
|
const res = await fetch('https://v2.jokeapi.dev/joke/Programming?type=single');
|
||||||
.then(res => res.json())
|
const json = await res.json();
|
||||||
.then(json => console.log(json.joke));
|
console.log(json.joke);
|
||||||
|
|
||||||
console.log('fetchDataFromApi() done.');
|
console.log('fetchDataFromApi() done.');
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue