无法在 React Native 中显示图像 [英] Can't show Image in React Native
问题描述
我使用的是 react-native 0.28.0
I'm using react-native 0.28.0
我正在尝试根据本教程在 iPhone 模拟器上显示图像:Introduction to React原生:用 JavaScript 构建 iOS 应用 |应用程序
I'm trying to show an image on iPhone simulator according to this tutorial: 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()
函数中,我添加:
Then in the render()
function, I add this:
<Image style={styles.image} source={{uri:imageURI}} />
为图像分配的空间在那里,但图像没有显示.
The space allocated for the image is there, but the image is not shown.
推荐答案
除了 Jonathan Stellwag 的回答之外,第一个解决方案仅在 URI 使用 https 或通过设置应用传输安全性时才有效.
In addition to Jonathan Stellwag's answer, the 1st solution only works if the URI is using https, or by setting the App Transport Security.
参见 无法显示图像React Native iOS Simulator 中的 URI
这篇关于无法在 React Native 中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!