簡體   English   中英

間歇性的“Bootstrap的JavaScript需要jQuery”錯誤

[英]Intermittent “Bootstrap's JavaScript requires jQuery” error

我剛剛開始使用requirejs,我遇到了一個我似乎無法解決的問題。 當我加載我的應用程序時,我偶爾會收到錯誤“Bootstrap的JavaScript需要jQuery”。 以下是相關文件:

.HTML

<html>
<head>
<link href="./css/bootstrap.min.css" rel="stylesheet">
<link href="./css/custom.css" rel="stylesheet">
<script data-main="scripts/main" src="scripts/vendor/require.js"></script>
</head>
<body>
...
</body>

來自main.js文件的my.config:

requirejs.config({
    baseUrl : './scripts',
    shim : {
        underscore : {
            exports : '_'
        },

        bootstrap : {
            dep : [ 'jquery'],
            exports: 'Bootstrap'
        },

        backbone : {
            deps : [ 'jquery', 'underscore' ],
            exports : 'Backbone'
        },

        marionette : {
            deps : [ 'jquery', 'underscore', 'backbone' ],
            exports : 'Marionette'
        },

        text: {
            deps : [ 'jquery', 'underscore', 'backbone' ],
            exports: 'Text'
        }
    },

    paths : {
        jquery : 'vendor/jquery.min',
        underscore : 'vendor/underscore',
        bootstrap : 'vendor/bootstrap.min',
        backbone : 'vendor/backbone',
        marionette : 'vendor/backbone.marionette',
        text: 'vendor/text'
    }
});

正如我所說,這不會一直發生,只是隨機發生。 有人可以看到我做錯了什么或者我怎么能找到問題?

謝謝

在這部分配置中:

bootstrap : {
            dep : [ 'jquery'],

它應該是deps而不是dep 使用dep ,就好像你根本沒有指定任何依賴項一樣,這意味着只有在jQuery 恰好在它之前加載 ,Bootstrap才會正常加載。 (另外,Bootstrap沒有定義Bootstrap符號,因此exports位無用。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM