简体   繁体   English

ReactJS登录页面未显示

[英]ReactJS login page not showing

I am following this tutorial: reactjs-and-laravel---running-through-a-basic-setup---part-2-20p 我正在学习本教程: reactjs-and-laravel ---通过基本设置运行--- part-2-20p

but I can't get the contents of the login page to show. 但我无法显示登录页面的内容。 I have: 我有:

Login.js Login.js

import React, { Component } from 'react';
import ReactDOM from 'react-dom';

export default class Login extends Component {

    constructor(props) {
        super(props);

        this.processSubmit = this.processSubmit.bind(this);
    }

    componentWillMount() {
        // do something like setting default state
    }

    processSubmit(values) {
        // do something with the values
    }

    render() {
        const { handleSubmit, submitting } = this.props;

        return (
            <div className="container mt-5">
                <div className="row justify-content-center">
                    <div className="col-6">
                        <div className="card">
                            <div className="card-body">
                                <h2 className="text-center font-weight-light mb-4">Sign into your account</h2>
                                <form onSubmit={handleSubmit(this.processSubmit)}>
                                    <Field
                                        label="Email Address"
                                        name="email"
                                        component={FormField}
                                        id="email"
                                        type="text"
                                        className="form-control"
                                    />
                                    <Field label="Password" name="password" component={FormField} id="password" type="password" className="form-control" />
                                    <div className="form-check">
                                        <label className="form-check-label">
                                            <Field name="remember" component="input" type="checkbox" className="form-check-input mt-2" value="1" />
                                            Remember me
                                        </label>
                                    </div>
                                    <div className="form-group mt-4">
                                        <button type="submit" className="btn btn-secondary" disabled={submitting}>Continue</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        );
    }
};

Login = reduxForm({
    form: 'login',
    validate
})(Login);

Which is imported into App.js : 哪个导入到App.js中

import React, {Component} from 'react'
import ReactDOM from 'react-dom'
import {BrowserRouter, Route, Switch} from 'react-router-dom'
import Home from '../containers/Home';
import Login from '../containers/LogIn';
import CreateUsers from '../containers/CreateUsers';
import Dashboard from '../containers/Dashboard';
import NavBar from './NavBar';

import {createStore, combineReducers} from 'redux';
import {reducer as formReducer} from 'redux-form';

import {Provider} from 'react-redux';

const rootReducer = combineReducers({
    form: formReducer,
});


const store = createStore(rootReducer);


class App extends Component {
    constructor(props) {
        super(props);

        this.state = {
            isAuthenticated: false
        };
    }

    userHasAuthenticated = authenticated => {
        this.setState({isAuthenticated: authenticated});
    };

    render() {
        return (
            <Provider store={store}>
                <BrowserRouter>
                    <div>
                        <NavBar />
                        <Route exact path="/" component={Home}/>
                        <Route path="/login" component={Login}/>
                        <Route path="/users/create" component={CreateUsers}/>
                        <Route path="/dashboard" component={Dashboard}/>
                    </div>
                </BrowserRouter>
            </Provider>
        )
    }
}

ReactDOM.render(<App />, document.getElementById('app'))

What am I doing wrong? 我究竟做错了什么?


Console is giving me: 控制台给我:

Uncaught ReferenceError: reduxForm is not defined 未捕获ReferenceError:未定义reduxForm


It now gives me Uncaught ReferenceError: validate is not defined 现在它给了我Uncaught ReferenceError:未定义验证


Now I am getting: 现在我得到:

Warning: Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function`.
    in Route (created by App)
    in App

As well as: 以及:

Uncaught ReferenceError: FormField is not defined

You are using reduxForm at the bottom of your Login.js but are not importing it. 您正在Login.js底部使用reduxForm,但未导入它。

import { reduxForm } from 'redux-form';

You can find details of installing and getting started in their docs: https://redux-form.com/8.1.0/docs/gettingstarted.md/ 您可以在他们的文档中找到安装和入门的详细信息: https : //redux-form.com/8.1.0/docs/gettingstarted.md/

You need to import reduxForm from redux-form library. 您需要从redux-form库导入reduxForm。 Before you import make sure you install it 导入之前,请确保已安装

Using 运用

npm i -s redux-form

And then import it in Login.js component 然后将其导入Login.js组件

import { reduxForm } from 'redux-form';

Remove validate from reduxForm 从reduxForm删除验证

Change 更改

  Login = reduxForm({
        form: 'login',
        validate
    })(Login);

To

  Login = reduxForm({
        form: 'login'
    })(Login);

Validate is actually a prop to redux Field component 验证实际上是对Redux Field组件的支持

For example 例如

     <Field
                                    label="Email Address"
                                    name="email"
                                    component={FormField}
                                    id="email"
                                    type="text"
                                    className="form-control"
                                    validate={[required, maxLength15, minLength2]}
                                />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM