【问题标题】:How to initialise bootstrap dismissable alert with webpack如何使用 webpack 初始化 bootstrap 可关闭警报
【发布时间】:2020-09-13 09:15:47
【问题描述】:

我正在通过 webpack 安装 Bootstrap,并单独加载 JS 文件:

import '../../../scss/app/app.scss';

import 'popper.js';
import 'bootstrap/js/dist/tooltip';
import 'bootstrap/js/dist/popover';
import 'bootstrap/js/dist/util';
import 'bootstrap/js/dist/dropdown';
import 'bootstrap/js/dist/modal';
import 'bootstrap/js/dist/tab';
import 'bootstrap/js/dist/collapse';

$(() => {
  $('[data-toggle="tooltip"]').tooltip();
  $('[data-toggle="popover"]').popover();
});

所有元素都按预期工作,除了可关闭的警报,单击按钮时不会消失:

<div class="alert alert-warning alert-dismissible fade show" role="alert">
  // Message here
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">×</span>
  </button>
</div>

我是否弄错了依赖项?我的理解是data api 应该自动初始化(docs)。所有下拉菜单、弹出框等似乎都可以正常工作,而且我没有控制台错误。

【问题讨论】:

    标签: javascript twitter-bootstrap webpack bootstrap-4 webpack-4


    【解决方案1】:

    我的笨蛋:

    import 'bootstrap/js/dist/alert';
    

    公平地说,这在引导程序 docs 中是缺失的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-06
      • 2011-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      相关资源
      最近更新 更多