gpt4 book ai didi

javascript - 为什么这个简单的 require.js 设置不起作用?

转载 作者:行者123 更新时间:2023-12-03 11:50:40 24 4
gpt4 key购买 nike

我正在尝试学习如何使用 require.js 加载我的脚本,但我的设置/理解有问题。我看不出有什么问题。这是我所缺少的简单设置。

当我在 Chrome 中加载此 index.html 页面时,脚本 require.js 操作均不起作用。

***index.html

<html>
<head>
<title>My Sample Project</title>
</head>
<body>
<h1 class="h1">sample project header</h1>
<script data-main="main" src="require.js"></script>
</body>
</html>

***main.js

(function() {
requirejs.config({
//By default load any module IDs from baseUrl
baseUrl: '',
// paths config is relative to the baseUrl, and
// never includes a ".js" extension
paths: {
'small-blue-mod': './a-script'
}
});

// Start the main app logic.
requirejs(['small-blue-mod'], function (sbm) {
alert(sbm.color);
});
})();

***小蓝-mod.js

define({
color: "blue",
size: "small"
});

*文件系统看起来像...

index.html
main.js
require.js
FOLDER called "a-script"

a-script 文件夹包含 small-blue-mod.js

最佳答案

路径small-blue-mod引用a-script文件夹,或者像small-blue-mod/small-blue-mod一样需要它 或建议将路径更改为:

paths: {
'small-blue-mod': './a-script/small-blue-mod'
}

关于javascript - 为什么这个简单的 require.js 设置不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25854370/

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