Fork me on GitHub

dva Form.create() 使用问题

这样有问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class loginPage extends React.Components {
...
handleSubmit (e) {
this.props.form.validateFields((err, values) => {
this.props.dispatch...
});
}
...
render () {
return (
<Form onSubmit={handleSubmit.bind(this)}>
<Form.Item>
{getFieldDecorator('username', {
rules: [{ required: true, message: '请输入您的邮箱!' }],
})(
<Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="邮箱" onChange={
e => {
this.props.dispatch...
}
} />
)}
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" onClick={
e => {
this.props.dispatch...
}
}>登录</Button>
</Form.Item>
</Form>
);
}
...
}
export default connect(({ loginData }) => ({ loginData }))(Form.create()(loginPage));

以上各处的 dispatch 都失效了
改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const loginPage = ({
loginData,
dispatch,
form: {
getFieldDecorator,
validateFields,
},
}) => {
const handleSubmit = (e) => {
validateFields((err, values) => {
dispatch...
});
}
...
return (
...
)
}
export default connect(({ loginData }) => ({ loginData }))(Form.create()(loginPage));

-------------感谢您的阅读 有问题请留言(或mailto:frostbelt@sina.cn)-------------