如下图所示
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5SZlRzN1QjY5YWM1MWMkVWOmRmZ0QTYzEjZ1I2MwQWNl9CX5d2bs92Yl1iclB3bsVmdlR2LcNWaw9CXt92Yu4GZjlGbh5yYjV3Lc9CX6MHc0RHaiojIsJye.png)
SAP UI5 框架在加载时,将 id 转换成 url:
sap/ui/demo/CombineLatest/Component.js,
然后在其头部,拼接上来自 id 为 sap-ui-bootstrap 里的 src 属性定义的 SAP UI5 库文件的前缀:
https://sapui5.hana.ondemand.com/resources/最后得到的路径:
https://sapui5.hana.ondemand.com/resources/sap/ui/demo/CombineLatest/Component.js显然,这个路径是错误的。因为 Component.js 仅仅存在于我们工程自身。
因此需要使用 data-sap-ui-resourceroots 告诉 SAP UI5 加载器,如果遇到前缀为 sap.ui.demo.CombineLatest 的本地资源文件,**不要使用 sap-ui-core.js **的前缀即
https://sapui5.hana.ondemand.com/resources,而是使用本地路径./
修改之后,资源加载成功,正确的路径应该是:http://localhost:3002/combine/Component.js
这个路径是怎么来的呢?
(1) Component.js 的 id 为 sap.ui.demo.CombineLatest.Component,因为 data-sap-ui-resourceroots 生效,将 sap.ui.demo.CombineLatest.Component 替换成 ./Component
(2) ./Component 替换成 URL:/Component.js
(3) ./之前的 url 为 localhost:3002/combine
得到最后的绝对路径去加载 Component.js:
http://localhost:3002/combine/Component.js