在 react-native 项目中将图像放在哪里? [英] Where to put images in a react-native project?

查看:123
本文介绍了在 react-native 项目中将图像放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 react-native 项目,目前我们正在将图像放在 /images/ 文件夹中.这对他们来说是一条好路吗?有什么最佳实践吗?

I am working on a react-native project and we are putting images currently in /images/ folder. Is it a good path for them ? Is there any best practice?

推荐答案

您可以将图像文件夹添加到 src(src/image/index.js).图像文件夹添加 index.js 文件创建并添加整个应用程序图像.在 index.js 文件集中

You can add image folder to src(src/image/index.js). Image folder add index.js file create and add whole app image. In index.js file set

export const IMAGENAME = require('./icon.png'); 

导入图片文件夹时

import { IMAGENAME } from '../image';

使用图片:

<Image source={ IMAGENAME } />

您可以将图像添加到图像文件夹并设置索引文件的路径.希望这对你有帮助.

You can add image to image folder and set path to index file. Hope this will help you.

这篇关于在 react-native 项目中将图像放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆