加载图像作为道具反应原生 [英] Load image passed as props react native

查看:60
本文介绍了加载图像作为道具反应原生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从道具加载图像时,出现以下错误警告:失败的道具类型:无效的道具 source 提供给 image这是我的代码

When I am trying to load image from props i am getting the following error warning: failed prop type: invalid prop source supplied to image Here is my code

src/components/common/Header.js

src/components/common/Header.js

<View style={viewStyle}>
  <Text style={textStyle}>{props.children}</Text>
  <Image style={{height:25, width:25}} source={props.imageUri} />
</View>

src/index.js

src/index.js

<Header imageUri='../../images/logout.png'>My App</Header>

图像位于路径 src/images/logout.png

and the image is at path src/images/logout.png

请帮忙

推荐答案

您的来源是错误的.

它应该使用 uri 属性.

要么使用 require:

Either you use require:

<Image source={require('.../../images/logout.png')} />

反过来,你也可以要求这个道具

in turn, you can then require this prop too

<Image source={require(props.imageUri)} />

或者您按原样使用 Uri:

Or you use the Uri as is:

<Image source={{uri: props.imageUri }} />

请参阅此处的文档了解更多详情

这篇关于加载图像作为道具反应原生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆