【发布时间】:2019-07-13 10:58:51
【问题描述】:
我正在组合一个 React 应用程序,该应用程序使用来自我本地计算机上的 Node/Express REST API 的数据。我有一个简单的res.json 返回一个 Sequelize 对象,我正在通过我创建的服务访问它。显然,我最终会将对象放入 state,但我目前无法访问这些值。
const options = {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: JSON.stringify({email: "matthewharp@gmail.com", password: "M1nerals"})
};
fetch('http://localhost:3000/users/sign_in', options)
.then(response => console.log(response.json()));
我在控制台中得到结果,但它们卡在 [[PromiseValue]] 中。
我一定错过了某种异步步骤,但我不确定是什么。
【问题讨论】:
-
fetch('http://localhost:3000/users/sign_in', options).then(response => response.json()).then(data => console.log(data));
标签: javascript ajax reactjs express