简体   繁体   English

反应bootstrap模态 - 我如何让它显示?

[英]react bootstrap modal - how do I get it to show?

I have a component in which I am importing reactBootstrap: 我有一个组件,我在其中导入reactBootstrap:

import ReactBootstrap from 'react-bootstrap'

Then I have a function in my component that's triggered when the user clicks a button: 然后我在我的组件中有一个函数,当用户单击按钮时会触发该函数:

onClickBtn : function() {
  var Modal = ReactBootstrap.Modal;
  return (
    <Modal>
      ... 
    </Modal>
  )
}

However, I get the error: 但是,我收到错误:

Uncaught TypeError : Cannot read property 'Modal' of undefined. 未捕获的TypeError:无法读取未定义的属性“模态”。

I am having trouble following the guide on react-bootstrap and I'm wondering if anyone knows how to easily import modal. 我在使用react-bootstrap指南时遇到了麻烦,我想知道是否有人知道如何轻松导入模态。 Thanks 谢谢

You can import any component directly from 'react-bootstrap' using the following es6 syntax: 您可以使用以下es6语法直接从'react-bootstrap'导入任何组件:

import { Component } from 'react-bootstrap';

In this particular case, you can use: 在这种特殊情况下,您可以使用:

import { Modal } from 'react-bootstrap';

You can also import multiple components at once, such as: 您还可以一次导入多个组件,例如:

import { Button, ButtonToolbar, Modal } from 'react-bootstrap';

The need for { } is because these are not default exports, they are named exports that can be referred to by name. 对{}的需求是因为它们不是默认导出,它们被命名为可以通过名称引用的导出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM