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