回答編集履歴

1

追記

2024/10/03 08:23

投稿

n23
n23

スコア22

test CHANGED
@@ -37,3 +37,32 @@
37
37
  })
38
38
  ...
39
39
  ```
40
+ ---
41
+ 10/3 16:25頃追記 への追加回答:
42
+ ```js
43
+ function fetchAuth(form) {
44
+ return fetch(`http://localhost:3000/login`, {
45
+ cache: "no-store",
46
+ method: "POST",
47
+ headers: { "Content-Type": "application/json" },
48
+ body: JSON.stringify(form),
49
+ })
50
+ .then((response) => response.json())
51
+ .then((data) => {
52
+ console.log(data.message);
53
+ return data.message;
54
+ })
55
+ .catch((e) => {
56
+ console.error('Network error:', error);
57
+ throw new Error('Network error occurred');
58
+ })
59
+ }
60
+
61
+ // 呼び出し側 ---------------
62
+ fetchAuth(form)
63
+ .then((message) => {
64
+ console.log(message);
65
+ })
66
+ .catch((e) => {
67
+ })
68
+ ```