搜索

首页  >  问答  >  正文

"react/jsx-no-undef错误:'Form'未定义"

<p>嗨,使用下面的React应用程序,我需要管理一个表单来验证登录到一个页面,参数是邮箱和密码,但是当我执行代码时,会打印出以下错误,错误:<strong>第33行:'Form'未定义react/jsx-no-undef</strong></p> <p><strong>Javascript代码:</strong></p> <pre class="brush:php;toolbar:false;">import React, { Component } from 'react'; import { Button, FormGroup, FormControl, ControlLabel } from "react-bootstrap"; import logo from './logo.svg'; import './Home.css'; class Home extends Component { constructor(props) { super(props); this.state = { email: "", password: "" }; } validateForm() { return this.state.email.length > 0 && this.state.password.length > 0; } handleChange = event => { this.setState({ [event.target.id]: event.target.value }); } handleSubmit = event => { event.preventDefault(); } render() { return ( <div className="Login"> <Form onSubmit={this.handleSubmit}> <Form.Group controlId="email" bsSize="large"> <Form.Control autoFocus type="email" value={this.state.email} onChange={this.handleChange} /> </Form.Group> <Form.Group controlId="password" bsSize="large"> <Form.Control value={this.state.password} onChange={this.handleChange} type="password" /> </Form.Group> <Button block bsSize="large" disabled={!this.validateForm()} type="submit" > 登录 </Button> </Form> </div> ); } } export default Home;</pre> <p><br /></p>
P粉501007768P粉501007768448 天前504

全部回复(1)我来回复

  • P粉238433862

    P粉2384338622023-08-25 10:55:37

    似乎你忘记导入 Form,只需添加它:

    import { Form, Button, FormGroup, FormControl, ControlLabel } from "react-bootstrap";

    回复
    0
  • 取消回复