簡體   English   中英

如何在獲取請求中添加對象數組

[英]how to add an array of objects in a fetch request

我正在嘗試添加一個包含對象數組的發布請求,但我被卡住了。 你能幫我指導我的問題在哪里嗎?

這是我的代碼

這是我想保存的

你應該使用 await 或者 then 如果你想使用那么你可以這樣做

fetch('you api', {
   method: 'POST',
   body: JSON.stringify({
     // here put data you want to send
   })
  })
  .then((response) => response.json())
  .then((json) => {
    // you can do what ever you want here
    console.log(json)
  }
)

或者如果你想使用 async-await 使用這個

const getData = async () => {
  const response = await fetch('your api', {
    method: 'POST',
    body: JSON.stringify({
      // your data
    }),
  });

  const data = await response.json();
  console.log(data);
  // do what ever you want here 

};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM