[英]Bootstrap and browserify problems whit 2 bundles
我有一个 web 页面,其中包含 2 个 Javascript 文件,一个是所有页面(捆绑包)共有的,另一个是页面特定的thispagespecific.js
。
在它们中,我必须包含文件bootstrap.js
,因为它不是全局的,并且我在它们中都使用了 modal。
它似乎在控制台中没有任何错误,但引导组件在某些时候停止工作:折叠触发很好,但我无法隐藏之后。
首先,一个引导程序被执行,另一个是另一个,因此它将再次可见。
我正在考虑让 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
最后,我能够解决我的问题,即让 bootstrap 全球化并且只调用一次。
globalThis.bootstrap = require('bootstrap/dist/js/bootstrap.bundle.min.js');
这使得所有页面甚至控制台上的全局和调用引导程序都可以工作。
也许有更酷的解决方案,但是....这至少对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.