【问题标题】:How can I fix this state error when I create a log storage in local storage?在本地存储中创建日志存储时如何解决此状态错误?
【发布时间】:2021-05-10 10:09:22
【问题描述】:

早上好,我收到一个语法错误,我不知道状态部分的问题是什么

 constructor(props) {
    super(props);

    this.onChangeName = this.onChangeName.bind(this);
    this.onChangeEmail = this.onChangeEmail.bind(this);
    this.onChangePassword = this.onChangePassword.bind(this);
    this.onSubmit = this.onSubmit.bind(this);

    this.state = {
        name = '',
        email = '',
        password = ''
    }
}



<form onSubmit={ this.onSubmit } >
                <input type='name' placeholder='Nombre' value={ this.state.name } onChange={ this.onChangeName } required />
                <input type='email' placeholder='Email' value={ this.state.email } onChange={ this.onChangeEmail } required />
                <input type='password' placeholder='Contraseña' value={ this.state.password } onChange={ this.onChangePassword } required />

error

【问题讨论】:

  • 使用半列而不是相等(例如名称:“fanjiloo”)

标签: javascript reactjs


【解决方案1】:

你正在定义一个对象,你必须使用冒号而不是等号:

  this.state = {
    name : '',
    email : '',
    password : ''
  }

【讨论】:

  • @fanjiooJr 将某些内容分配给变量时,您必须使用等号 - 但在对象内部,将某些内容分配给对象的属性时,您必须使用冒号 - 就像在我的示例中一样 -你可以快速尝试,只需将代码复制到浏览器的控制台中
猜你喜欢
  • 2019-07-08
  • 2012-06-27
  • 2019-09-20
  • 2011-05-09
  • 2019-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多