加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

twitter-bootstrap – Shim Twitter Bootstrap for RequireJS

发布时间:2020-12-18 00:02:00 所属栏目:安全 来源:网络整理
导读:RequireJS docs说,要支持旧版本的IE,您需要配置enforceDefine:true。 So if you want to support Internet Explorer,catch load errors,and have modular code either through direct define() calls or shim config,always set enforceDefine to be true
RequireJS docs说,要支持旧版本的IE,您需要配置enforceDefine:true。

So if you want to support Internet Explorer,catch load errors,and have modular code either through direct define() calls or shim config,always set enforceDefine to be true. See the next section for an example.

NOTE: If you do set enforceDefine: true,and you use data-main=”” to load your main JS module,then that main JS module must call define() instead of require() to load the code it needs. The main JS module can still call require/requirejs to set config values,but for loading modules it should use define().

由于Twitter Bootstrap不是AMD模块,我需要对它进行填充以使其工作。
这是我如何配置它;

<script type="text/javascript">
    var require = {
        paths: {
            "bootstrap": "../bootstrap","jquery": "../jquery-1.8.2"
        },shim: {
            "bootstrap": ["jquery"]
        },enforceDefine: true
    };
</script>

后来当我的模块需要引导作为依赖,我仍然最终得到一个错误消息;

Error: No define call for bootstrap

http://requirejs.org/docs/errors.html#nodefine

如果我已正确理解文档,enforDefines应忽略垫片,但它不是。

我在这里做错了什么?

解决方法

根据文档,如果“脚本是shim配置的一部分,指定一个全局字符串属性,可以检查加载,并且检查失败,则抛出错误。

要解决这个问题,您需要在shim配置中添加导出值,以便RequireJS可以检查脚本是否已成功加载。如果Bootstrap有点棘手,因为Bootstrap不会导出一个属性全局变量只有一堆jquery插件,但你可以使用任何这些插件作为导出值。 $ .fn.popover:

{
    paths: {
        "bootstrap": "../bootstrap","jquery": "../jquery-1.8.2"
    },shim: {
        "bootstrap": {
          deps: ["jquery"],exports: "$.fn.popover"
        }
    },enforceDefine: true
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读