Harmony 鸿蒙应用开发之解决 Web 组件加载本地资源跨域问题
鸿蒙开发文档中有一节 加载本地页面 提到了可以通过 $rawfile
方法加载本地 HTML 网页:
1 | Web({ src: $rawfile("local.html"), controller: this.webviewController }) |
但是如果在 local.html 中需要引用一些静态资源,例如图片、JS、CSS 等,静态资源放在 local.html 同级目录下,会出现跨域的错误:
1 | Access to ... at 'resource://...' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, arkweb, data, chrome-extension, chrome, https, chrome-untrusted. |