我按照教程&他們使用event.preventDefault()
上的Save
按鈕&保存表格到狀態。我還沒有真正寫過input
標籤,但到目前爲止我已經添加了保存按鈕,它有點像重新加載它不應該做的頁面。event.preventDefault未在React中工作
這是我的頁面組件:
class manageLocationPage extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
};
this.SaveLocation = this.SaveLocation.bind(this);
}
componentWillMount() {
}
componentDidMount() {
}
SaveLocation(event) {
event.preventDefault();
console.log("Saved");
}
render() {
return (
<div>
<LocationForm listingData={this.props.listingData} onSave={this.SaveLocation}/>
</div>
);
}
}
我locationForm
組件:
const LocationForm = ({listingData, onSave, loading, errors}) => {
return (
<form>
<h1>Add/Edit Location</h1>
<TextInput />
{/*Here below is where we submit out input data*/}
<input type="submit" disabled={loading} value={loading ? 'Saving...' : 'Save'} className="buttonSave" onClick={onSave}/>
</form>
);
};
我錯過了什麼?
如果你使用'form'的'onSubmit'呢? – zerkms