1
我得到这样的错误在我ReactJS应用,遗漏的类型错误:无法创建于字符串“财产'empFirstName”
遗漏的类型错误:无法创建属性“”上线“”
empFirstName这个错误显示在浏览器控制台后,我清除文本框使用清除按钮,并尝试键入。
代码如下:
import React from 'react';
import fetch from 'isomorphic-fetch';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';
import FormErrors from './FormErrors.js';
export default class EmployeeRegister extends React.Component {
constructor() {
super();
this.state = {
empFirstName: ''
}
this.handleChange = this.handleChange.bind(this);
this.clearFields = this.clearFields.bind(this);
}
handleChange(event) {
const target = event.target;
const value = target.value;
const name = target.name;
this.setState({[name]: value})
});
}
clearFields() {
this.setState({empFirstName: ''})
}
render() {
return (
<div>
<div className="row">
<div className="col-sm-12">
<h2>Employee Register Form</h2>
</div>
</div>
<form>
<div className="row">
<div className="col-sm-6">
<div className="form-group">
<label htmlFor="empFirstName">First Name : </label>
<input type="text" className="form-control" id="empFirstNameTxt" value={this.state.empFirstName}
name="empFirstName"
onChange={this.handleChange}/>
</div>
</div>
</div>
<div className="row">
<input type="submit" value="Submit" className="btn btn-primary" id="submitBtn" />
<input type="button" value="Clear"
className="btn btn-warning"
onClick={this.clearFields}/>
</div>
</form>
</div>
);
}
};
是的,得到它的感谢。 –
欢迎。 @ B.Arun – Ved