gpt4 book ai didi

javascript - 按名称要求模块仅在 Debug模式下受支持,并且会在生产中中断

转载 作者:行者123 更新时间:2023-11-30 15:23:01 25 4
gpt4 key购买 nike

我有一个文本和图像列表,我从 Firebase 数据库中获取图像的名称,然后将提取的名称与我项目下图​​像文件夹的路径连接起来:这就是我使用的代码

var icon=  require ('path/'+item.image+'.png')

return (
...
<Image style={{width: 50, height: 50}}
source={icon}/>

图像已显示,但我收到的警告与列表中的图像一样多我在某处读到这个

REQUIRE('IMAGE!...') NO LONGER SUPPORTED

Support for require('image!…'), which has been deprecated for a long time, is now removed. If you are still loading images that way in your apps, make sure to check the documentation for alternatives.

enter image description here

最佳答案

没有明确的问题被问到,所以我假设你在问“这个错误是什么意思?”以及“如果有的话,我应该怎么做才能让它消失?”。

require('image!...') 是在 React Native 中使用图像的(真正的)旧方法。但我怀疑您的问题是您正在动态构建图像名称。

参见 React Native docs on images :

In order for this to work, the image name in require has to be known statically.

// GOOD
<Image source={require('./my-icon.png')} />

// BAD
var icon = this.props.active ? 'my-icon-active' : 'my-icon-inactive';
<Image source={require('./' + icon + '.png')} />

// GOOD
var icon = this.props.active ? require('./my-icon-active.png') :
require('./my-icon-inactive.png');
<Image source={icon} />

所以不要动态地建立你的图像名称。

是的,我感受到了你不得不为世界上所有国家编写一个 switch-case 的痛苦......

关于javascript - 按名称要求模块仅在 Debug模式下受支持,并且会在生产中中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43413497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com