gpt4 book ai didi

javascript - 如何在 AMD 声明的 Dojo 模块中链接依赖项?

转载 作者:行者123 更新时间:2023-12-03 01:25:23 25 4
gpt4 key购买 nike

我不明白在定义模块时如何链接加载程序调用,因为定义需要返回但本身不返回任何内容,所以我不知道该怎么做。

define([
'require',
'https://code.jquery.com/jquery-3.3.1.min.js',
],
function (require) {
//Should I use a require or define...? I don't understand, none works
return define([
'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js'
],
function() {
const myModule = {...};
return myModule;
})
});

我必须执行上述操作的原因是因为我需要在加载 bootstrap 之前加载 jquery,因为 AMD 加载程序是异步的,而 Bootstrap 要求 jquery 已经加载。

最佳答案

您可以使用requirejs的配置选项。不熟悉 dojo 但通常你会做这样的事情:

require.config({
paths: {
'jquery': 'pathTo/jquery.min',
'bootstrap': 'pathTo/bootstrap.min'
},
shim: {
'bootstrap': { deps: ['jquery'] }
}
})

有关需要配置的更多信息 here

关于javascript - 如何在 AMD 声明的 Dojo 模块中链接依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51575180/

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