【问题标题】:I'm not able to get images to load into an Image component我无法将图像加载到图像组件中
【发布时间】:2020-06-09 20:47:51
【问题描述】:

您好,我是 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/>

【问题讨论】:

  • 这个Image组件是第三方库还是从react-native导入的?

标签: ios image react-native ios-simulator


【解决方案1】:

我认为问题在于您没有为 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)}
/>

【讨论】:

  • Akila,你成功了.. 非常感谢你解决了我的问题
  • @BenTait Gald 有帮助 :) 不要忘记将此标记为正确答案
  • 阿基拉不是故意的。已恢复
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-19
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多