我的应用程序的项目结构是:-
root
|-assets
|-icons
|-heart.png
|-components
|-basic
|-like.js
我想要实现的是将图像heart.png
导入到like.js
,其中包含以下代码:-
import React,{ Component } from 'react';
import{ View, Text, AppRegistry } from 'react-native';
class Example extends Component {
render ()
{
return(
<Image src= {require('./assets/icons/heart.png')} />
);
}}
export default Example;
它产生以下错误:-
ENOENT: no such file or directory, scandir 'C:\Users\gagan\sapora\android\sapora\components\basic\assets\icons'
使用source
代替使用src
render ()
{
return(
<Image source = {require('../assets/icons/heart.png')} />
);
}