• 使用React写的一个小小的登录验证密码组件


    哎,算了。直接上代码吧,不懂得私聊我把

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>有条件的渲染</title>
        <script src="./bower_components/react/react.production.min.js"></script>
        <script src="bower_components/react/react-dom.production.min.js"></script>
        <script src="bower_components/babel/browser.js"></script>
    </head>
    <body>
    <div id="test"></div>
    </body>
    <script type="text/babel">
        function Info(props) {
            if(!props.open){
                return null
            }
            return (
                    <p>{props.text}</p>
            )
        }
        class Login extends React.Component {
            constructor(props) {
                super(props);
                this.state = {text: "",resultText:"",open:false};
            }
    
            changeText(event) {
                this.setState({text: event.target.value})
            }
    
            changeStatus() {
                this.setState({open: true})
                if (!this.state.text) {
                    this.setState({
                        resultText:"您还未登录"
                    })
                } else if (this.state.text == "123456") {
                    this.setState({
                        resultText:"您好,您已登录"
                        }
                    )
                } else {
                    this.setState({
                        resultText:"不好意思,密码错误"
                    })
                }
            }
                render(){
                return (
                    <div>
                           <input placeholad="请输入您的密码" type="text" value={this.state.text} onChange={e => this.changeText(e)}/>
                        <button onClick={this.changeStatus.bind(this)} >点击登录</button>
                        <Info text={this.state.resultText} open={this.state.open}></Info>
                    </div>
                )
            }
    
        }
        ReactDOM.render(
                <Login/>,
            document.getElementById("test")
        )
    </script>
    </html>
    

      

      

  • 相关阅读:
    Spring注解@Resource和@Autowired区别对比
    Http请求中Content-Type讲解以及在Spring MVC中的应用
    解决SpringMVC的@ResponseBody返回中文乱码
    JVM之类加载器下篇
    JVM之类加载器中篇
    JVM之类加载器上篇
    HashMap的resize和Fail-Fast机制
    HashMap的实现原理
    Tomcat中JVM内存溢出及合理配置
    redis的主从复制,读写分离,主从切换
  • 原文地址:https://www.cnblogs.com/mmykdbc/p/8582885.html
Copyright © 2020-2023  润新知