【发布时间】:2016-07-14 04:57:05
【问题描述】:
我遵循了一个教程,他们在Save 按钮上使用了event.preventDefault() 并将表单保存到状态中。我还没有真正写过input 标签,但到目前为止我已经添加了保存按钮,它有点像重新加载它不应该做的页面。
这是我的页面组件:
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呢?
标签: javascript reactjs preventdefault