我在react中有一个表单,而不是redux表单,我希望表单是自动提交的。这是我的代码:
class DummyForm extends React.Component {
constructor(props) {
super(props);
this.state = { value: '' };
this.handleChange = this.handleChange.bind(this);
this.onLoadEvent = this.onLoadEvent.bind(this);
}
componentWillMount() {
this.onLoadEvent();
}
onLoadEvent() {
this.document.forms.threedfrom.submit();
}
handleChange(event) {
this.setState({ value: event.target.value });
}
render() {
return (
<body>
<form
name="threedfrom"
action={this.props.acsUrl}
method="POST"
>
<textarea
style={{ display: 'none' }}
name="PaReq"
value={this.props.pareqMessage}
/>
<input
type="hidden"
name="MD"
value={this.props.reservationCode}
/>
<input type="submit" value="Submit" />
</form>
</body>
);
}
}
但是当组件被挂载时,我得到了一个错误Uncaught TypeError:Cannot read property'forms'of undefined意味着文档是未定义的。这怎么可能?我错过了什么?谢谢