使用react-bootstrap模式时,无法读取未定义的属性'Header'

问题描述 投票:2回答:3

我在我的项目中使用react-bootstrap。在使用Modal组件时出现如下错误。

enter image description here

模态组件:

<Modal  show={this.state.modalshow} onHide={close}  container={this} aria-labelledby="contained-modal-title">
   <Modal.Header closeButton>
     <Modal.Title id="contained-modal-title">Add User</Modal.Title>
   </Modal.Header>
reactjs bootstrap-modal react-bootstrap
3个回答
0
投票

尝试在顶部添加

import Modal from 'react-bootstrap/lib/Modal';
// or
import { Modal } from 'react-bootstrap';

0
投票

在First Install React bootstrap中使用以下命令 -

npm install --save react-bootstrap

之后从react-bootstrap导入Modal

import {Button,Modal} from 'react-bootstrap'
<Button bsStyle="primary" type="submit">Create</Button>

如果这个代码适合你,即react-bootstrap工作正常,尝试使用你的模态代码将工作正常。 否则你的react-bootstrap安装有问题。


0
投票

这似乎不是莫代尔问题。如果你使用任何未定义的值,它就会发生,但这并不意味着Modal.Header没有未定义。 enter image description here enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.