2017-03-21 54 views
3

當我試圖從道具我收到以下錯誤 警告加載圖像:失敗道具類型:提供給image 這裏無效道具source是我的代碼加載圖像通過道具反應本地

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

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

和圖像在路徑的src /圖片/ logout.png

請幫助

回答

1

對於本地圖片路徑語法

<Image style={{height:25, width:25}} source={require(props.imageUri)} /> 
1

是錯誤的。

它應該使用uri屬性。

無論您使用要求:

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

反過來,你就可以要求該道具太

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

或者你使用URI作爲是:

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

Refer to the documentation for more details here

+0

應該是什麼專業版要傳入的pType? –