【问题标题】:Bootstrap and browserify problems whit 2 bundlesBootstrap 和 browserify 问题与 2 个捆绑包
【发布时间】:2019-10-24 11:39:22
【问题描述】:

我有一个包含 2 个 Javascript 文件的网页,一个是所有页面通用的(捆绑),另一个是页面特定的 thispagespecific.js

在这两个文件中,我必须包含文件 bootstrap.js,因为它不是全局的,并且我在它们两个中都使用了 modal。

它似乎在控制台中没有任何错误,但引导组件在某些时候停止工作:collapse 触发良好,但之后我无法隐藏。
首先,一个引导程序被执行,另一个是另一个,因此它将再次可见。

我正在考虑让 Bootstrap 全球化,但我不知道这是否正确。

有什么帮助吗?谢谢!

HTML

 <script src="../js/bundle.js"></script>
 <script src="../js/thisPageSpecific.js"></script>

main.js(browserfy 后的 bundle.js)

var $ = require('jquery');
var bootstrap = require('bootstrap/dist/js/bootstrap.bundle.min.js');
//... more requires
$('#menu').modal('show');
//... more code

thisPageSpecific.js

var $ = require('jquery');
var bootstrap = require('bootstrap/dist/js/bootstrap.bundle.min.js');
$('#pagespecificid').modal('show');
//... more code

【问题讨论】:

    标签: javascript twitter-bootstrap browserify


    【解决方案1】:

    最后我能够解决我的问题,即使引导程序全局化并且只调用一次。

    globalThis.bootstrap = require('bootstrap/dist/js/bootstrap.bundle.min.js');
    

    这使得所有页面甚至控制台都可以使用全局和调用引导程序。

    也许有一个 cooler 解决方案,但是....这至少对我有用。

    【讨论】:

      猜你喜欢
      • 2017-12-21
      • 2015-03-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 2023-03-31
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多