gpt4 book ai didi

requirejs - 依赖关系未定义 - RequireJS

转载 作者:行者123 更新时间:2023-12-02 23:14:56 26 4
gpt4 key购买 nike

我正在尝试将 OpenLayers 库与 RequireJS 一起使用。

问题是,OpenLayers 一直处于“未定义”状态,即使它被列为我的模块的唯一依赖项:

define(['OpenLayers'],function (OpenLayers) {
console.log(OpenLayers);
});

这将打印“未定义”。

如果我用jquery替换OpenLayers(两个.js文件都在同一个文件夹中),它将不再是未定义的。

那么为什么 RequireJS 没有加载 OpenLayers 呢?

最佳答案

这段代码对我有用:

require.config({
shim: {
OpenLayers: {
exports: 'OpenLayers'
}
}
});

require(['OpenLayers'], function(OpenLayers) {
console.log(OpenLayers);
});

关于requirejs - 依赖关系未定义 - RequireJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12839478/

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