javascript – require.js模块未正确加载

前端之家收集整理的这篇文章主要介绍了javascript – require.js模块未正确加载前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有我的bootstrap文件定义了require.js路径,并加载了app和config模块.
// Filename: bootstrap

// Require.js allows us to configure shortcut alias
// There usage will become more apparent futher along in the tutorial.
require.config({
    paths: {
        bfwd: 'com/bfwd',plugins: 'jquery/plugins',ui: 'jquery/ui',jquery: 'jquery/jquery.min','jquery-ui': 'jquery/jquery-ui.min',backbone: 'core/backbone.min',underscore: 'core/underscore.min'
    }
});
console.log('loading bootstrap');
require([
    // Load our app module and pass it to our definition function
    'app','config'
],function(App){
    // The "app" dependency is passed in as "App"
    // Again,the other dependencies passed in are not "AMD" therefore don't pass a parameter to this function
    console.log('initializing app');
    App.initialize();
});

app.js是像它应该加载的,它的依赖关系被加载.调用它的定义回调,所有正确的依赖关系作为参数传递.没有错误被抛出.然而,在bootstrap的回调中,App是未定义的!没有参数被通过.可能是什么原因造成的?这是我的应用程序文件(修改为空格)

// Filename: app.js
define(
    'app',[
        'jquery','underscore','backbone','jquery-ui','bfwd/core','plugins/jquery.VistaProgressBar-0.6'
    ],function($,_,Backbone){
        var initialize = function()
        {
            //initialize code here
        }
        return 
        {
            initialize: initialize
        };
    }
);

解决方法

据我所知,你应该可以在app.js define方法中放置“app”字符串.
// Filename: app.js
define([
    'jquery','plugins/jquery.VistaProgressBar-0.6'
],Backbone){
    ...
);
原文链接:https://www.f2er.com/js/150081.html

猜你在找的JavaScript相关文章