簡體   English   中英

Saga Redux未在后期發送參數

[英]Saga Redux not sending parameters in post

我第一次使用redux Saga處理我的API請求。 我有一個異步函數,可以發送一個簡單的發布請求,如下所示:

const onLoginRequest = async (userName, password) =>
await fetch(`${loginApi}`, { method: 'POST', body: { userName:userName,password:password } })
  .then(res => res.json())
  .then(res => res)
  .catch(error => error);

如果我在查詢字符串中發送用戶名和密碼,則可以正常工作。 但是,當將它們添加到我的POST正文中時,它大喊它們是未定義的。

知道我在做什么錯嗎?

確保按以下方式序列化JSON正文

body: JSON.stringify({
  userName: userName,
  password: password
})

暫無
暫無

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

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