回答編集履歴
4
コメント追加
test
CHANGED
@@ -6,14 +6,14 @@
|
|
6
6
|
async function getTodo() { // async関数は必ずPromiseを返す
|
7
7
|
try {
|
8
8
|
const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
|
9
|
-
return res.data.title; // .then
|
9
|
+
return res.data.title; // Promise.thenに代わってawaitで戻り値を受け取れる
|
10
10
|
} catch (err) {
|
11
11
|
return "error";
|
12
12
|
}
|
13
13
|
}
|
14
14
|
|
15
15
|
async function main() {
|
16
|
-
const todo = await getTodo(); // getTodo()はPromise、awaitでPromiseから戻り値を取
|
16
|
+
const todo = await getTodo(); // getTodo()はPromise、awaitでPromiseから戻り値を受け取る
|
17
17
|
console.log(todo);
|
18
18
|
}
|
19
19
|
|
3
コメント追記
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
async function getTodo() { // async関数は必ずPromiseを返す
|
7
7
|
try {
|
8
8
|
const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
|
9
|
-
return res.data.title;
|
9
|
+
return res.data.title; // .thenの代わりにawaitで戻り値を受け取れる
|
10
10
|
} catch (err) {
|
11
11
|
return "error";
|
12
12
|
}
|
2
コメント追記
test
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
```js
|
4
4
|
import axios from "axios";
|
5
5
|
|
6
|
-
async function getTodo() {
|
6
|
+
async function getTodo() { // async関数は必ずPromiseを返す
|
7
7
|
try {
|
8
8
|
const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
|
9
9
|
return res.data.title;
|
1
コメント追記
test
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
}
|
14
14
|
|
15
15
|
async function main() {
|
16
|
-
const todo = await getTodo();
|
16
|
+
const todo = await getTodo(); // getTodo()はPromise、awaitでPromiseから戻り値を取り出す
|
17
17
|
console.log(todo);
|
18
18
|
}
|
19
19
|
|