"react/jsx-no-undef錯誤:'Form'未定義"
P粉501007768
2023-08-24 11:45:53
<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>
似乎你忘記導入
Form
,只要加入它: