以下是RN document中Image
的示例:
import React, { Component } from 'react';
import { AppRegistry, View, Image } from 'react-native';
export default class DisplayAnImage extends Component {
render() {
return (
<View>
<Image
source={require('/react-native/img/favicon.png')}
/>
</View>
);
}
}
对于本地图像文件,它使用source = {require('path-to-image-file')}
。我的渲染代码如下:
<View>
<Image
style={{width:150, height:100,borderRadius:13,margin:3, resizeMode:'cover'}}
source={require("./image1.jpg")} //<<tested working for image file resides in the same subdir of component
/>
</View>
我正在尝试将uri: ""
的格式转换为source
。这是尝试的字符串列表,不适用于位于组件相同子目录中的本地文件image1.jpg
:
source={{uri: "./image1.jpg"}}
source={{uri: "/image1.jpg"}}
source={{uri: "image1.jpg"}}
source={{uri: "file:///image1.jpg"}}
source={{uri: "file: //image1.jpg"}}
source={{uri: "file:/image1.jpg"}}
source={{uri: "file: image1.jpg"}} //<<== syntax error
uri
源的正确格式是什么?