简体   繁体   English

如何查看 react-native 中变量的值?

[英]How can I to see the value of variable in react-native?

 fetch('https://localhost:3000/api/usuario/login', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ userName: user, Userpassword: password console.log(Userpassword) //-- > BUT THIS DOSEN´ T WORK; }) });

I can see the value of variable userName for example, the value of userName .我可以看到变量 userName 的值,例如userName的值。

You are putting it in the wrong location.你把它放在错误的位置。

 console.log(Userpassword); // this ok fetch('https://localhost:3000/api/usuario/login', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ userName: user, Userpassword: password }) });

Place the console statement outside.console语句放在外面。 Like this:像这样:

console.log("User: ", user);
console.log("Password: ", password);

fetch('https://localhost:3000/api/usuario/login', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    userName: user,
    Userpassword: password
  })
});

And you have to use the actual variable names: "user" and "password", not "userName" or "Userpassword".你必须使用实际的变量名:“user”和“password”,而不是“userName”或“Userpassword”。 These are the keys of the object you are sending in the request.这些是您在请求中发送的 object 的密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM