[英]react - TypeError: Cannot read property 'trim' of undefined
I'm not sure what I'm doing wrong here. 我不确定我在做什么错。
class Login extends Component {
render() {
const username = "me@domain.com ";
console.log(username)
const password = this.refs.password;
const creds = {
username: username.value.trim(),
password: password.value.trim()
};
const errorMessage = this.props;
return ( ... ) } }
console shows "me@domain.com" yet it's erroring on username: username.value.trim()
控制台显示“ me@domain.com”,但
username: username.value.trim()
错误
11 | console.log(username)
12 | const password = this.refs.password;
13 | const creds = {
> 14 | username: username.value.trim(),
15 | password: password.value.trim()
16 | };
17 | const errorMessage = this.props;
username.value.trim()
username
itself a String, you need not to get value out of it. username
本身是一个字符串,您无需从中获取价值。 Just trim. 修剪一下
const creds = {
username: username.trim(),
password: password.value.trim()
};
username
is not an object
but a string string and hence you would write username
不是object
而是字符串,因此您将编写
const username = "me@domain.com ";
const creds = {
username: username.trim(),
password: password.trim()
};
Also you shouldn't use string refs
as they are deprecated. 同样,您不应该使用
string refs
因为它们已被弃用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.