H5调用出现跨域问题,日志错误:
Access to fetch at 'xxx' from origin 'xxx' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."
还请参考下以下方法:
(1)可以使用web组件的loadData接口,用于加载指定的数据,该接口的参数baseUrl可以实现:入参baseUrl可以指定的一个URL路径("http"/"https"/"data"协议),并由Web组件赋值给window.origin。通过该接口更改协议可以解决跨域问题。
(2)通过customizeSchemes接口,isSupportCORS表示是否支持跨域请求。schemeName表示自定义协议名称。https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-webview-V5\#customizeschemes