React-native WebView:从资产文件夹加载 html 和 js

React-native WebView: Load html and js from assets folder

我需要从 WebView 的资产文件夹加载 html 和 js 文件。我试过使用:

<WebView source={{uri: "file:///android_asset/index.html"}} />

连同 javaScriptEnabled={true}。 html 文件已加载,但 XMLHttpRequest 停止工作。我想这是由于 'file' 协议。

有没有其他方法可以在不使用 file:/// 的情况下访问 assets 文件夹中的文件?或者就此而言,此问题的任何其他解决方案。

找到路了。 使用 react-native-static-server 创建服务器并加载 html 文件。