将本地图像处理到应用程序中-得到sha1错误



我正在尝试制作一个带有附加图像的notes应用程序。当用户添加图像时,我会将其保存到服务器,然后在服务器中保存图像的路径。

{this.state.img ? <Image
style={stylesCP.image}
source={{ uri: require(this.state.img)}}
></Image> : null}

img状态包含:/Users/myUser/Study/Rect Native/Note/WebApplication1/WebApplication1/images/1_3_2021_5_06_PMg.jpg

我得到了这个错误:

Failed building JavaScript bundle.

文件/Users/myUser/Study/Rect Native/Note/WebApplication1/WebApplication1/images/1_3_2021_5_08_PMimg.jpg(/Users/my User/Study/Rect Native/Note/WebApplication1/WebApplication1/images/1_3_2021_5_06_08_PMimg.jpg(的SHA-1未计算

有人能帮我吗?

您需要正确指定本地图像语法和路径,如下所示,试试这个让我知道

class ImageExample extends Component {
constructor(props) {
super(props);
this.state = {
img: require('../../Assests/Images/1_3_2021_5_06_08_PMimg.jpg'),
};
}
render() {
return (
<View>
{
this.state.img ?
<Image
source={this.state.img}
/>
: null
}
</View>
);
}
}
export default ImageExample;

最新更新