gpt4 book ai didi

javascript - Backbone.js 和 Require.js : Mismatched anonymous define() module: function (_, 主干){

转载 作者:行者123 更新时间:2023-12-01 01:46:13 24 4
gpt4 key购买 nike

我刚开始使用 require.js,并且将以下 app.js 文件作为我的主干应用程序的一部分:

require.config({
baseUrl: "/js/",
paths: {
jquery: 'libs/jquery-2.1.0',
underscore: 'libs/underscore-min',
backbone: 'libs/backbone-min'
},
shim: {
underscore: {
exports: "_"
},
backbone: {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
}
});

在我的 index.html 文件的标签中,我放置了以下内容:

define(['underscore', 'backbone'], function (_, Backbone) {

但是,我的 index.html 文件出现以下错误:

Uncaught ReferenceError: Backbone is not defined

我的 require.js 文件中包含以下内容:

Uncaught Error: Mismatched anonymous define() module: function (_, Backbone) {

有什么线索吗?

最佳答案

我正在使用上面的配置,

as you can see is there minimals diffs

正如您所看到的,将我的示例图像与您的声明方式进行比较,是否存在最小差异:

  • 您不需要在路径声明shim库,只需使用相同的名称
  • 我的 baseUrl 从我的 js\lib 文件夹开始;
  • 我在 json 配置中使用文件名;

当我在我的主 html 页面上声明“设置”时,我会这样使用:

<script data-main="js/setup.js" src="js/lib/require.js"></script>

关于javascript - Backbone.js 和 Require.js : Mismatched anonymous define() module: function (_, 主干){,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23143506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com