我正在寻找如何从本地路径加载图像到WebView。这是为了将其插入到MapView的信息窗口中(在Android上出现问题)。当我使用URL时,它可以正常工作,但使用本地路径却不行。
<WebView
originWhitelist={['*']}
source={{html: '<Body><img id="logo" src="../../assets/img.jpg" onload="onLoad()" /></Body>'}}
/>
我正在寻找如何从本地路径加载图像到WebView。这是为了将其插入到MapView的信息窗口中(在Android上出现问题)。当我使用URL时,它可以正常工作,但使用本地路径却不行。
<WebView
originWhitelist={['*']}
source={{html: '<Body><img id="logo" src="../../assets/img.jpg" onload="onLoad()" /></Body>'}}
/>
我尝试了几个选项,唯一有效的是:
1)创建一个index.html文件,在其中可以使用常规的图像路径:
<html>
<body>
<img src="./dog.jpg" width="200" height="200" />
</body>
</html>
2) 在你的WebView
中加载index.html文件
<WebView
originWhitelist={['*']}
source={require('./index.html')}
/>
我尝试过的无法解决问题的方法:
<WebView
originWhitelist={['*']}
source={{html: `<Body><img id="logo" width=200 height=200 src="./dog.jpg" /></Body>`}}
/>
<WebView
originWhitelist={['*']}
source={{html: `<Body><img id="logo" width=200 height=200 src="require('./dog.jpg')" /></Body>`}}</Body>`}}
/>
import dog from './dog.jpg'
<WebView
originWhitelist={['*']}
source={{html: `<Body><img id="logo" width=200 height=200 src="${dog}" /></Body>`}}
/>