【问题标题】:Meteor including bootstrap and jQueryMeteor 包括 bootstrap 和 jQuery
【发布时间】:2015-02-19 02:50:00
【问题描述】:

我在添加 jQuery 和 Bootstrap 后立即收到错误消息。我添加的三个文件是

1) a_jquery-1.11.2.min.js // so that it is processed before 'b' in bootstrap
2) bootstrap.min.css
3) bootstrap.min.js

它们位于/lib

如果我在没有 jQuery 的情况下添加 bootstrap,我会收到一条错误消息,提示 Bootstrap 需要 jQuery。添加 jQuery 后,我收到以下错误消息。

/Users/username/.meteor/packages/meteor-tool/.1.0.40.cbg34i++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:173
            throw(ex);
                  ^
TypeError: Cannot call method 'createElement' of undefined
    at jb (app/lib/a_jquery-1.11.2.min.js:2:7547)
    at app/lib/a_jquery-1.11.2.min.js:2:22045
    at app/lib/a_jquery-1.11.2.min.js:2:22746
    at c (app/lib/a_jquery-1.11.2.min.js:2:207)
    at app/lib/a_jquery-1.11.2.min.js:2:212
    at app/lib/a_jquery-1.11.2.min.js:6:3
    at /Users/username/my_app/.meteor/local/build/programs/server/boot.js:205:10
    at Array.forEach (native)
    at Function._.each._.forEach (/Users/username/.meteor/packages/meteor-tool/.1.0.40.cbg34i++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)

有人知道我错过了什么吗?

编辑:我还有一个关于包含样式表的问题。我在/client/views/layout.html 中包含一个CDN 引导程序,但是一旦我删除导入行并将本地bootstrap.min.css 文件保存在/lib 中,样式就会开始中断。为什么会这样?

【问题讨论】:

    标签: meteor


    【解决方案1】:

    /lib 文件夹用于共享代码,将客户端框架放入其中会给您带来很多麻烦,因为 Meteor 也会尝试在服务器上运行它(并且在查找 window 对象时非常失败) .请将任何仅限客户端的代码放在 client 文件夹中。

    另外,我建议taking a look at packages 而不是自己做,很多人已经做了你正在经历的事情。

    如果您想拥有本地样式表,请将它们放在client 文件夹(立即加载)或public 文件夹(通过导入延迟加载)。更多关于documentation中的特殊文件夹。

    【讨论】:

      【解决方案2】:

      您不能将它们放在 /lib 中,因为其中的任何内容也由服务器加载。 /client/lib 没问题。

      还请注意,您不需要 jQuery,它是默认提供的(Blaze 使用它)。

      最后,我建议使用引导程序包。如果您使用this one,那么您将能够利用所有的mixin 并干净地更改基本变量。请参阅this article 了解更多信息。

      【讨论】:

        猜你喜欢
        • 2017-09-27
        • 1970-01-01
        • 2016-12-07
        • 2023-04-11
        • 2014-10-31
        • 2010-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多