react-native中使用webview踩过的坑(1)
最近项目中使用rn的webview进行加载本地H5页面,发现webview用路径加载会出现随机性的不显示问题。IOS暂未发现此问题。查了好久解决方案终于解决了。。。
解决方案
let pathUrl = 'file:///data/user/0/********/files/00010002/www/index.html'; //下载到本机的H5文件路径
fetch(pathUrl)
.then(res => res.text())
.then(htmlString => {
webviewParams = {
source: {
html:htmlString, //需要在webview中显示的静态页面
baseUrl: pathUrl
}
}
resolve(webviewParams);
})
.catch(error => {
alert('读取html文件异常!');
reject(error);
});