动态响应本机负载映像 [英] React Native load image dynamically
本文介绍了动态响应本机负载映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法可以这样加载图像吗?
Is there any way to load an image this way?
var x = './img/a.jpg';
<Image source={require(x)}/>
我需要使用它,因为我想动态加载图像.
I need to use this because I want to load the image dynamically.
推荐答案
只需创建对象并按以下方式使用
Simply you can create object and use it as follows
const images = {
foo: require('./img1.png'),
bar: require('./img2.png'),
}
<Image source={images.foo} />
这篇关于动态响应本机负载映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文