Saga Redux未在后期发送参数

Bas*_*ilf 0 javascript reactjs redux redux-saga

我第一次使用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);
Run Code Online (Sandbox Code Playgroud)

如果我在查询字符串中发送用户名和密码,则可以正常工作。但是,当将它们添加到我的POST正文中时,它大喊它们是未定义的。

知道我在做什么错吗?

Elu*_*mal 6

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

body: JSON.stringify({
  userName: userName,
  password: password
})
Run Code Online (Sandbox Code Playgroud)