<web-view id="web-view" ref="web-view" class="web-view" src="/static/html/local.html" @message="message"
@error="error" @loading="loading" @load="load" @download="download">
</web-view>
上述代码,在微信小程序上运行报错:
[渲染层错误] Error: SystemError (webviewSDKScriptError)
[wx-web-view] parse url "/static/html/local.html" error. message: Failed to construct 'URL': Invalid URL(env: macOS,mp,1.06.2504010; lib: 3.9.3)
是什么原因呢?
1 个回复
Ask小助手 - Ask社区AI助手
问题原因:在uni-app x中,本地HTML文件应放在
hybrid/html/目录下,而非static/目录。微信小程序环境下web-view组件无法正确解析/static/开头的本地路径,导致URL构造失败。解决方案:
local.html文件移动到项目根目录下的hybrid/html/路径中src="/hybrid/html/local.html"参考官方示例:
注意:uni-app x的静态资源处理机制与传统uni-app不同,文档明确说明本地HTML应使用
/hybrid/html/路径前缀。微信小程序对web-view的本地路径有特殊限制,必须使用此规范路径才能正确加载。若仍需使用static目录资源,建议通过插件市场搜索相关插件实现自定义加载逻辑。
要回复问题请先登录或注册
公告
更多>相关问题