Created
February 8, 2018 08:11
-
-
Save tfanme/0ceeb532444d63093e16d4206b67185e to your computer and use it in GitHub Desktop.
使用一个对象作为 React 组件的配置,从而实现动态生成组件内容
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Input, Icon } from 'antd'; | |
import styles from './index.less'; | |
const map = { | |
UserName: { | |
component: Input, | |
props: { | |
size: 'large', | |
prefix: <Icon type="user" className={styles.prefixIcon} />, | |
placeholder: 'admin', | |
}, | |
rules: [{ | |
required: true, message: '请输入账户名!', | |
}], | |
}, | |
Password: { | |
component: Input, | |
props: { | |
size: 'large', | |
prefix: <Icon type="lock" className={styles.prefixIcon} />, | |
type: 'password', | |
placeholder: '888888', | |
}, | |
rules: [{ | |
required: true, message: '请输入密码!', | |
}], | |
}, | |
Mobile: { | |
component: Input, | |
props: { | |
size: 'large', | |
prefix: <Icon type="mobile" className={styles.prefixIcon} />, | |
placeholder: '手机号', | |
}, | |
rules: [{ | |
required: true, message: '请输入手机号!', | |
}, { | |
pattern: /^1\d{10}$/, message: '手机号格式错误!', | |
}], | |
}, | |
Captcha: { | |
component: Input, | |
props: { | |
size: 'large', | |
prefix: <Icon type="mail" className={styles.prefixIcon} />, | |
placeholder: '验证码', | |
}, | |
rules: [{ | |
required: true, message: '请输入验证码!', | |
}], | |
}, | |
}; | |
export default map; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment