我使用的是react native 0.28.0

根据本教程,我试图在iPhone模拟器上显示一幅图像:

Introduction to React Native: Building iOS Apps with JavaScript | Appcoda

var styles = StyleSheet.create({
image: {
    width: 107,
    height: 165,
    padding: 10
  }
}

var imageURI = 'http://books.google.com/books/content?id=PCDengEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api'

然后在render()函数中,我添加以下内容:

<Image style={styles.image} source={{uri:imageURI}} />

为图像分配的空间在那里,但图像未显示.


但是,如果我使用本 map 像,则会显示图像.

var Picture = require('./content.jpeg')

render()功能中:

<Image source={Picture} style={styles.thumbnail} />

如何使用URI作为源显示图片?

推荐答案

问题是,你的用户试图从http连接加载图像,而不是按照苹果的要求从https连接加载图像.

如果您的代码使用的是另一个使用https而不是http的uri,请try .

更多信息请访问

如果你真的想通过http加载一些东西,你可以编辑这些信息.plist文件并在那里添加您的异常.更多详细信息请点击这里:Configuring App Transport Security Exceptions in iOS 9 and OSX 10.11.

另请参见我的问题:React-native loading image over https works while http does not work.

React-native相关问答推荐

使用NextJS映射从数组中提取用户角色

如何在renderItem中显示每个项目的索引号,保持分页的前一个下一个按钮

替换数组中的一个元素就是替换数组中的所有元素?

未执行迁移?

构建 iOS Expo 应用时出现 React-Native xcodebuild 错误 65

如何将 react-native 图像从 expo-image-picker 上传到使用 multer 的 Express.js 后端

如何判断 Detox 正在运行测试?

如何在 React Navigation 5 中将父函数传递给子屏幕?

React Native - Expo:fontFamily 'SimpleLineIcons' 不是系统字体,尚未通过 Font.loadAsync 加载

如何在 React Native 的无状态功能组件中扩展原生组件的 props TypeScript 接口?

TabNavigator 中的 React Navigation 传递props

Visual Studio 代码错误:-Failed to start flow Error: Wrong version of Flow. The config specifies version ^0.92.0 but this is version 0.95.1

为了回调 URL 的目的,在 Expo 中运行的 React Native 元素的 info.plist 在哪里?

如何启用 stacktrace react-native run-android 命令?

eslint Parsing error: Unexpected token =

React 中的 getSnapshotBeforeUpdate() 是什么?

当组件在react-native 中重新呈现时,动态不透明度不会改变

查找文本输入框和按钮字段的资源名称以响应本机 android 应用程序

React-Native Invariant Violation:元素类型无效

键盘可见时无法单击按钮