Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 反应本机映像-未知的命名模块'/img/2.jpeg';_React Native - Fatal编程技术网

React native 反应本机映像-未知的命名模块'/img/2.jpeg';

React native 反应本机映像-未知的命名模块'/img/2.jpeg';,react-native,React Native,我正在尝试修改react redux教程代码。我正在尝试加载本地存储的图像,路径保存在对象中 ... { "id": 2, "title": "Redux", "subtitle": "A State of Mind", "img": "../img/3.jpeg", "description": "Redux is a predictable state container for JavaScript apps. It helps you write

我正在尝试修改react redux教程代码。我正在尝试加载本地存储的图像,路径保存在对象中

...
{
    "id": 2,
    "title": "Redux",
    "subtitle": "A State of Mind",
    "img": "../img/3.jpeg",
    "description": "Redux is a predictable state container for JavaScript apps. It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test."
  },
...
我有以下错误(我重新启动了模拟器几次)

未知的命名模块:“../img/3.jpeg”

这是容器(eslint还说-unexpected require())

import React,{Component}来自'React';
进口{
文本,
可触摸且无反馈,
看法
布局动画,
形象
}从“反应本机”;
从'react redux'导入{connect};
从“/common”导入{CardSection};
将*作为动作从“../actions”导入;
类ListItem扩展组件{
componentWillUpdate(){
layoutimation.spring();
}
renderDescription(){
const{library,expanded}=this.props;
如果(扩展){
返回(
{library.subtitle}
{library.description}
);
}
}
render(){
常量{titleStyle}=样式;
const{id,title}=this.props.library;
返回(
this.props.selectLibrary(id)}
>
{title}
{this.renderDescription()}
);
}
}
常量样式={
标题样式:{
尺码:18,
paddingLeft:15
},
描述样式:{
paddingLeft:10,
填充右:10
},
图像样式:{
身高:100,
宽度:100,
背景颜色:“黑色”
}
};
const mapStateToProps=(state,ownProps)=>{
const expanded=state.selectedLibraryId==ownProps.library.id;
返回{扩展};
};
导出默认连接(MapStateTrops,actions)(列表项);

除了映像,一切正常-只是映像不在那里。

您不能在React Native中动态地要求映像,或者静态地执行,或者像这样使用uri:

source={{ uri: library.img }}
但是考虑到你必须把你的图像放在这条路径下

anroid/app/src/main/res/drawable
创建
drawable
文件夹(如果未创建)

并更新json文件以删除
。/


请参阅本期:

谢谢。这消除了错误,但它呈现的是空白,而不是图像。不过,感谢我在ios上这么做。
anroid/app/src/main/res/drawable