Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Image 动态路径在本机中不工作_Image_React Native - Fatal编程技术网

Image 动态路径在本机中不工作

Image 动态路径在本机中不工作,image,react-native,Image,React Native,下面是代码 require("index/components/" + name); //fails require("index/components/myComponent"); //work fine 有什么好的解决方案吗?我不确定,但你可以试着用ES6编写 require(`index/components/${name}`)当前不支持require中的动态路径。 请核对答案 “静态资源”一节中的文档介绍了这一点: 引用捆绑包中的映像的唯一方法是在源代码中直接写入require

下面是代码

  require("index/components/" + name); //fails
  require("index/components/myComponent"); //work fine

有什么好的解决方案吗?

我不确定,但你可以试着用ES6编写


require(`index/components/${name}`)

当前不支持require中的动态路径。 请核对答案

“静态资源”一节中的文档介绍了这一点:

引用捆绑包中的映像的唯一方法是在源代码中直接写入require(“资产名称”)


您可以使用
switch
语句来实现这一点。

名称是什么?…您在哪里为名称变量赋值,以及哪些值?你能添加整个代码吗?`const path=
。/../../../assets/Static_Icons/${name}.${fileType}
;`iconSrc=require(路径)`