'ControlLabel' 未从 'react-bootstrap' 导出
'ControlLabel' is not exported from 'react-bootstrap'
你好,我正在 React 中创建一个登录表单,使用包的 Checkbel 检查登录参数,但是当我 运行 代码时,我抛出了这个异常:。 /src/App.js Attempted import error: 'ControlLabel' is not exported from 'react-bootstrap'. 我该如何解决?
反应代码:
import React, { Component } from "react";
import { Form,Button, FormGroup, FormControl, ControlLabel } from "react-bootstrap";
import "./Login.css";
import Bootstrap from "react-bootstrap";
export default class Login 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}>
<FormGroup controlId="email" bsSize="large">
<ControlLabel>Email</ControlLabel>
<FormControl
autoFocus
type="email"
value={this.state.email}
onChange={this.handleChange}
/>
</FormGroup>
<FormGroup controlId="password" bsSize="large">
<ControlLabel>Password</ControlLabel>
<FormControl
value={this.state.password}
onChange={this.handleChange}
type="password"
/>
</FormGroup>
<Button
block
bsSize="large"
disabled={!this.validateForm()}
type="submit"
>
Login
</Button>
</form>
</div>
);
}
}
根据这个 url https://react-bootstrap.github.io/components/buttons/#button-props 和你的版本,你应该像这样修改你的代码。
import React, { Component } from "react";
import Form from 'react-bootstrap/Form'
import Button from 'react-bootstrap/Button'
import Bootstrap from "react-bootstrap";
export default class Login 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"
>
Login
</Button>
</Form>
</div>
);
}
}
尝试使用 FormLabel 而不是 ControlLabel。
这个 "react-bootstrap": "^1.0.0-beta.16",
不包含 ControlLabel,所以
使用
卸载它
npm uninstall react-bootstrap
然后使用此 "react-bootstrap": "^0.32.4"
版本重新安装
npm install react-bootstrap@0.32.4 --save
一定会解决这个问题
<ControlLabel>
来自旧版本的 react-bootstrap。当前版本 ("react-bootstrap": "^1.4.3") 使用 <FormLabel>
或 <Form.Label>
你好,我正在 React 中创建一个登录表单,使用包的 Checkbel 检查登录参数,但是当我 运行 代码时,我抛出了这个异常:。 /src/App.js Attempted import error: 'ControlLabel' is not exported from 'react-bootstrap'. 我该如何解决?
反应代码:
import React, { Component } from "react";
import { Form,Button, FormGroup, FormControl, ControlLabel } from "react-bootstrap";
import "./Login.css";
import Bootstrap from "react-bootstrap";
export default class Login 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}>
<FormGroup controlId="email" bsSize="large">
<ControlLabel>Email</ControlLabel>
<FormControl
autoFocus
type="email"
value={this.state.email}
onChange={this.handleChange}
/>
</FormGroup>
<FormGroup controlId="password" bsSize="large">
<ControlLabel>Password</ControlLabel>
<FormControl
value={this.state.password}
onChange={this.handleChange}
type="password"
/>
</FormGroup>
<Button
block
bsSize="large"
disabled={!this.validateForm()}
type="submit"
>
Login
</Button>
</form>
</div>
);
}
}
根据这个 url https://react-bootstrap.github.io/components/buttons/#button-props 和你的版本,你应该像这样修改你的代码。
import React, { Component } from "react";
import Form from 'react-bootstrap/Form'
import Button from 'react-bootstrap/Button'
import Bootstrap from "react-bootstrap";
export default class Login 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"
>
Login
</Button>
</Form>
</div>
);
}
}
尝试使用 FormLabel 而不是 ControlLabel。
这个 "react-bootstrap": "^1.0.0-beta.16",
不包含 ControlLabel,所以
使用
npm uninstall react-bootstrap
然后使用此 "react-bootstrap": "^0.32.4"
版本重新安装
npm install react-bootstrap@0.32.4 --save
一定会解决这个问题
<ControlLabel>
来自旧版本的 react-bootstrap。当前版本 ("react-bootstrap": "^1.4.3") 使用 <FormLabel>
或 <Form.Label>