如何正確取得 fetch 的狀態?
P粉124070451
P粉124070451 2023-09-08 18:25:24
0
1
409

我在我的 api 中執行提取,它返回 201 狀態,但是當我嘗試在變數中接收它時,狀態變得很奇怪。

useEffect(() => {
async function Verify (test) {
 await fetch("/api/test", {
  method: "POST", 
  headers: {
   'Content-Type': 'application/json',
  },
  body: JSON.stringify({test: test}),
 }).then((response) => {
  res = response.status; 
  console.log(res); //thats print '201'
  return res;
 });
}
const status = Verify(test);
console.log(status); //thats print 'Promise { <state>: "fulfilled", <value>: 201 }'

}

P粉124070451
P粉124070451

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!