无法在输入字段中输入

Gam*_*007 2 reactjs

我有以下代码:

    constructor(props) {
        super(props);
        this.state = {
            search: "",
            value: "",
            username:'',
            email:'',
            password: '',
        };

        this.onChange = this.onChange.bind(this);
        this.onSubmit = this.onSubmit.bind(this);
    }

...
...

    onChange(e) {
        this.setState(
            {[e.target.name]: e.target.value})
    }

...
...

<input type="password" placeholder="Password"
onChange={e => this.onChange(e)}
value={ this.state.password }
                                                />
Run Code Online (Sandbox Code Playgroud)

但是我无法在密码字段中输入。如果删除该value={ this.state.password }零件,则可以在该字段中键入内容,但是当更改此字段时,状态似乎没有更新。

问题是什么?

Pav*_*van 5

您忘记在密码字段中输入名称。它应该是

<input 
 type="password" 
 placeholder="Password"
 name="password"
 onChange={e => this.onChange(e)}
 value={ this.state.password }
/>
Run Code Online (Sandbox Code Playgroud)