React實(shí)現(xiàn)登錄表單的示例代碼
作為一個(gè)Vue用戶,是時(shí)候擴(kuò)展一下React了,從引入antd、配置less、router,終于實(shí)現(xiàn)了一個(gè)簡(jiǎn)單的登錄表單。

代碼如下:
import React from 'react';
import { Input, Button, message } from "antd";
import { UserOutlined, LockOutlined, EyeInvisibleOutlined, EyeTwoTone } from '@ant-design/icons';
import './index.less'
class Login extends React.Component{
constructor(props) {
super(props)
this.state = {
username: '',
password: ''
}
};
submit=()=>{
if (this.state.username !== '' && this.state.password !== '') {
this.props.history.push('/Index')
} else {
message.error("用戶名和密碼不能為空")
}
};
user_change=(e)=>{
this.setState({
username: e.target.value
})
}
password_change=(e)=>{
this.setState({
password: e.target.value
})
}
render () {
const {username, password} = this.state
return (
<div className="login">
<Input
value={username}
onChange={this.user_change}
size="large"
placeholder="用戶名"
prefix={<UserOutlined />} />
<Input.Password
value={password}
onChange={this.password_change}
size="large"
className="login__input"
placeholder="密碼"
prefix={<LockOutlined />}
iconRender={visible => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
/>
<Button
className="login__btn"
size="large"
type="primary"
onClick={this.submit}
>
登錄
</Button>
</div>
);
}
}
export default Login;
到此這篇關(guān)于React實(shí)現(xiàn)登錄表單的示例代碼的文章就介紹到這了,更多相關(guān)React 登錄表單內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
React引入antd-mobile+postcss搭建移動(dòng)端
本文給大家分享React引入antd-mobile+postcss搭建移動(dòng)端的詳細(xì)流程,文末給大家分享我的一些經(jīng)驗(yàn)記錄使用antd-mobile時(shí)發(fā)現(xiàn)我之前配置的postcss失效了,防止大家踩坑,特此把解決方案分享到腳本之家平臺(tái),需要的朋友參考下吧2021-06-06
使用react context 實(shí)現(xiàn)vue插槽slot功能
這篇文章主要介紹了使用react context 實(shí)現(xiàn)vue插槽slot功能,文中給大家介紹了vue的slot的實(shí)現(xiàn)方法,需要的朋友可以參考下2019-07-07
react配合antd組件實(shí)現(xiàn)的管理系統(tǒng)示例代碼
這篇文章主要介紹了react配合antd組件實(shí)現(xiàn)的管理系統(tǒng)示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04
使用Node搭建reactSSR服務(wù)端渲染架構(gòu)
這篇文章主要介紹了使用Node搭建reactSSR服務(wù)端渲染架構(gòu),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-08-08

