React-bootstrap“未找到”选项。
尝试在注册表单中添加下拉菜单。
import React from 'react';
import { Form, Option } from 'react-bootstrap';
function Signup() {
return (
<Form>
<Form.Group className='mb-3' controlId='firstName'>
<Form.Label>First Name</Form.Label>
<Form.Control type='firstName' placeholder='First name' required />
</Form.Group>
<Form.Group className='mb-3' controlId='lastName'>
<Form.Label>Last Name</Form.Label>
<Form.Control type='firstName' placeholder='Last name' required />
</Form.Group>
<Form.Group className='mb-3' controlId='email'>
<Form.Label>Email</Form.Label>
<Form.Control type='email' placeholder='Email address' required />
</Form.Group>
<Form.Select aria-label='TeamSelect'>
<Option>Select your team</Option>
<Option value='1'>Team One</Option>
<Option value='2'>Team Two</Option>
</Form.Select>
</Form>
)
}
export default Signup
如果我这样留下它,那么我会遇到错误
ERROR in ./src/components/pages/Signup.js 156:43-49
export 'Option' (imported as 'Option') was not found in 'react-bootstrap/Form' (possible exports: default)
,但是如果我将“选项”排除在导入中,则会得到一个不确定的错误。 我在这里想念什么?
编辑1:我安装了react-bootstrap-select-dropdown,我不再遇到“选项”缺少“选项”的错误,但是页面不加载(白屏)。
Trying to add a dropdown menu in a signup form.
import React from 'react';
import { Form, Option } from 'react-bootstrap';
function Signup() {
return (
<Form>
<Form.Group className='mb-3' controlId='firstName'>
<Form.Label>First Name</Form.Label>
<Form.Control type='firstName' placeholder='First name' required />
</Form.Group>
<Form.Group className='mb-3' controlId='lastName'>
<Form.Label>Last Name</Form.Label>
<Form.Control type='firstName' placeholder='Last name' required />
</Form.Group>
<Form.Group className='mb-3' controlId='email'>
<Form.Label>Email</Form.Label>
<Form.Control type='email' placeholder='Email address' required />
</Form.Group>
<Form.Select aria-label='TeamSelect'>
<Option>Select your team</Option>
<Option value='1'>Team One</Option>
<Option value='2'>Team Two</Option>
</Form.Select>
</Form>
)
}
export default Signup
If I leave it as this then I get an error
ERROR in ./src/components/pages/Signup.js 156:43-49
export 'Option' (imported as 'Option') was not found in 'react-bootstrap/Form' (possible exports: default)
But If I leave 'Option' out of the import then I get an undefined error.
What am I missing here?
EDIT 1: I installed react-bootstrap-select-dropdown and I no longer get an error that 'Option' is missing however the page doesn't load (white screen).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用资本“ O”的“选项”用于反应,但不用于ReactJ。需要使用小写'o'作为“选项”才能下拉以工作。
'Option' with a capital 'O' is used in React-Native but not in ReactJS. Need to use lowercase 'o' for 'option' to get dropdown to work.