<div id="app">
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-primary" id="modalBtn">
    Launch demo modal
  </button>

  <!-- Modal -->
  <!-- Modal -->
  <div class="modal fade" id="modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h1 class="modal-title fs-5" id="exampleModalLabel">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">Save changes</button>
        </div>
      </div>
    </div>
  </div>
//擷取dom
const modalBtn = document.querySelector("#modalBtn");
const modal = document.querySelector("#modal");
//實體化,產生modal真的實體myModal
const myModal = new bootstrap.Modal(modal);

//我們打算在畫面一進入的時候,就把modal打開來可以使用.show()
// myModal.toggle();
// myModal.show();
modalBtn.addEventListener("click", function () {
  myModal.show();
});

External CSS

  1. https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.3/js/bootstrap.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.37/vue.global.prod.min.js