Forget password in React JS

前端 未结 1 1562
旧时难觅i
旧时难觅i 2021-01-28 18:34

In my log in page I have a button \"Forget my password\", I need, when I click in this button to go to the correct page.

In my current code, when I clic

相关标签:
1条回答
  • 2021-01-28 19:19

    Please try this example:

    import React from "react";
    
    export default class Login extends React.Component {
        constructor(props) {
            super(props);
            this.state = {forgot: false};
        }
    
        login() {
            alert('Login will work here');
        }
        forgot() {
            this.setState({forgot: true})
        }
    
        render() {
            return (
                <div>
                    {this.state.forgot === false && <div>
                        Username: <input/> <br/>
                        Password: <input/><br/>
                        <button onClick={this.forgot.bind(this)}>Forgot</button>
                        <button onClick={this.login.bind(this)}>Login</button>
                    </div>}
                    {this.state.forgot === true && <ForgotPassword/>}
                </div>
            );
        }
    }
    
    class ForgotPassword extends React.Component {
    
        reset() {
            alert('Password is sent to your email');
        }
    
        render() {
            return (<div><h1>Write your email</h1>
                <input/>
                <button onClick={this.reset.bind(this)}>Reset Password</button>
    
            </div>)
        }
    }
    
    0 讨论(0)
提交回复
热议问题