我的文件结构如下:
- 模块/
- 测试模块/
- js/
- main.js
- 查看/
- 查看.html
在 requireJs 配置中,我定义了我的 test_module
。
require.config({
baseUrl: "./",
packages: [
{
name: 'test_module',
location: 'modules/test_module/js'
}
]
});
后来我加载 test_module ,如下所示:
require(['test_module']);
问题是当我尝试使用 require.toUrl('../view/view.html')
从 main.js 模块获取 view.html 的 url 时,它返回 './view/view.html'
,但如果我尝试这样 require.toUrl('./view/view.html')
它会按预期返回结果 './modules/test_module/js/view/view.html'
我创建了 plunker 来演示我面临的问题 link here .
最佳答案
我明白了。
不知道这是否是最好的解决方案,但是 require.toUrl('./) + '../view/view.html'
对我来说效果很好。
关于javascript - RequireJS require.toUrl ('../' )无法按我的预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36057335/