Bootstrap 无法显示模态代替代码为模态显示在这页的底部

sg24os4d  于 2023-03-16  发布在  Bootstrap
关注(0)|答案(1)|浏览(190)

请我有问题显示一个模态与bootstrap 5。我没有使用react-bootstrap,所以我不能使用状态切换模态,我使用cdn与dom操作显示模态在一个页面上。而不是模态显示代码打开。x1c 0d1x
这是密码

import React from "react";
import { Modal } from "bootstrap";

const editProduct = () => {
  let modalWrapper = null;
  modalWrapper = document.createElement(
    "div"
  ).innerHTML = `<div class="modal fade modal-dialog modal-dialog-scrollable" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="staticBackdropLabel">Modal title</h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Understood</button>
      </div>
    </div>
  </div>
</div>
`;
  document.body.append(modalWrapper);
  let modal = new Modal(modalWrapper.querySelector(".modal"));
  modal.show();
};

export default editProduct;

我们会很感激你的帮助。谢谢

vhmi4jdf

vhmi4jdf1#

我不得不yarn add bootstrap,然后import 'bootstrap/dist/css/bootstrap.css',然后import { Modal } from "bootstrap";,然后let modal = new Modal(document.querySelector(".modal"));,而且我必须分两步来完成这个过程,它才能工作

modalWrapper = document.createElement("div");
  modalWrapper.innerHTML = `.....`

相关问题