在 TypeScript 中使用 antd 的 form 表单
如果你想在 TypeScript 中使用 antd 的 from 表单,在使用 Form.create() 方法时编辑器会报各种各样的错误,这是因为你没有规定 form 表单的 interface。
如何使用?
代码如下
import React, {PureComponent} from 'react'
import {Form} from 'antd'
import {FormComponentProps} from 'antd/lib/form/Form' // 获取 form 表单的 interface
interface IProps { // 定义所需的相应接口
onSave : any,
onEdit : any,
handlevisible : any
}
class FromModal extends PureComponent<IProps & FormComponentProps> {constructor(props: IProps & FormComponentProps) {super(props);
}
render () {
return (<Form layout="vertical"></Form>)
}
}
export default Form.create<IProps & FormComponentProps>()(FromModal)