首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react.js应用程序中iframe下的Reactstrap模式

react.js应用程序中iframe下的Reactstrap模式
EN

Stack Overflow用户
提问于 2018-12-18 19:55:17
回答 1查看 2.1K关注 0票数 0

我正在用react.js制作一个应用程序,并使用react-frame-component来创建iframe。在iframe中,我为Modal (reactstrap)编写了代码。此模式将在我的应用程序窗口中打开。我只想让它在iframe中打开。

在reactstrap git repo中创建了相关问题。如果您知道任何覆盖Modal的document对象的方法,请让我知道。问题:https://github.com/reactstrap/reactstrap/issues/1326

应用链接:https://q8lp3kyr5w.codesandbox.io/

代码:https://codesandbox.io/s/q8lp3kyr5w

组件

代码语言:javascript
复制
import React from "react";
import ReactDOM from "react-dom";
import { Modal, ModalBody, Button } from "reactstrap";
import Frame from "react-frame-component";
import "bootstrap/dist/css/bootstrap.min.css";
import "./styles.css";

class ModalComp extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      modal: false
    };

    this.toggle = this.toggle.bind(this);
  }

  toggle() {
    this.setState({ modal: !this.state.modal });
  }

  render() {
    return (
      <div>
        <Frame>
          <Button onClick={this.toggle}>Toggle Modal</Button>
          <Modal isOpen={this.state.modal} toggle={this.toggle}>
            <ModalBody>
              <br />
              Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum,
              ipsam? A id numquam inventore, cumque debitis similique eos
              maiores provident? Sed alias odit fuga, repellat ducimus
              voluptatum aliquid quis pariatur?
            </ModalBody>
          </Modal>
        </Frame>
      </div>
    );
  }
}

const App = () => (
  <div>
    <b>How to open modal in this iframe?</b>
    <ModalComp />
  </div>
);

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

css:

代码语言:javascript
复制
.App {
  font-family: sans-serif;
  text-align: center;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-20 14:06:24

到目前为止,reactstrap还没有提供将文档作为道具进行传递的功能。您可以使用react-modal。请参阅有问题的github问题链接。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53832479

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档