Electron.js 应用程序:Bootstrap 下拉菜单无法打开

问题描述

我正在尝试在我的第一个 Electron.js 应用中使用 Bootstrap。下拉按钮确实出现,但当我点击按钮时菜单本身没有出现。我怀疑我将 Bootstrap 和 jQuery 添加到应用程序的方式有问题。

这是我的index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Magic</title>
    <script>let $ = require('jquery');</script>
    <script>require('popper.js');</script>
    <script>require('bootstrap');</script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="index.css" />
  </head>
  <body>

    <img src="../assets/true.png">

    <h1>Magic Demo!</h1>
    <p>Welcome to the most magical demo ever!</p>

    <div class="dropdown">
      <button class="btn btn-secondary dropdown-toggle"
              type="button"
              id="dropdownMenu2"
              data-toggle="dropdown"
              aria-haspopup="true"
              aria-expanded="false">
        Dropdown
      </button>
      <div class="dropdown-menu" aria-labelledby="dropdownMenu2">
        <button class="dropdown-item" type="button">Action</button>
        <button class="dropdown-item" type="button">Another action</button>
        <button class="dropdown-item" type="button">Something else here</button>
      </div>
    </div>

  </body>
</html>

我通过 npm 添加了 BootstrapjQueryPopper.js,这是我的相关部分package.json

"dependencies": {
    "bootstrap": "^4.6.0","electron-log": "^4.3.2","electron-squirrel-startup": "^1.0.0","jquery": "^3.6.0","popper.js": "^1.16.1"
  },

此外,我发现在 Electron DevTools 上,我收到错误消息: "Uncaught ReferenceError: require is not defined"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)