嗨,我是JS和React Native的新手。我似乎无法将任何图像加载到Image组件中。我使用所有安全的uri并首先在浏览器中对其进行测试。它们会加载到浏览器中,但不会加载到我的ios模拟器中。似乎也没有错误。希望有人见过
下面是代码摘录:
<Image
source = { {uri:"https://images.freeimages.com/images/large-previews/f37/cloudy-scotland-1392088.jpg" }}
resizeMode = {"contain"}
onLoadStart = { () => alert("start")}
onLoadEnd = { () => alert("loaded") }
onError = {(e)=> alert(e.nativeEvent.error)}
/>
info.plist摘录:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
答案 0 :(得分:2)
我认为问题在于您尚未为Image组件指定任何样式。需要将图像的宽度和高度添加到图像样式中,以便将其显示在设备上。 More
尝试一下
<Image
source={{
uri:
"https://images.freeimages.com/images/large-previews/f37/cloudy-scotland-1392088.jpg"
}}
style={{ width: 100, height: 100 }} //Add this
resizeMode={"contain"}
onLoadStart={() => alert("start")}
onLoadEnd={() => alert("loaded")}
onError={e => alert(e.nativeEvent.error)}
/>