我正在研究一个本机反应项目,我们正在将图像放在/images/文件夹中.这对他们来说是一条好路吗?有没有最好的做法?
Nid*_*tel 35
您可以将图像文件夹添加到src(src/image/index.js).图像文件夹添加index.js文件创建并添加整个应用程序图像.在index.js文件集中
export const IMAGENAME = require('./icon.png');
Run Code Online (Sandbox Code Playgroud)
导入图像文件夹时
import { IMAGENAME } from '../image';
Run Code Online (Sandbox Code Playgroud)
使用图片:
<Image source={ IMAGENAME } />
Run Code Online (Sandbox Code Playgroud)
您可以将图像添加到图像文件夹并将路径设置为索引文件.希望这会帮助你.
小智 9
要将静态图像添加到您的应用程序,请将其放置在源代码树中的某个位置并像这样引用它:
<Image source={require('./my-icon.png')} />
Run Code Online (Sandbox Code Playgroud)
请参阅以下链接以获取更多解释:
https://facebook.github.io/react-native/docs/images.html
小智 7
在图像资产文件夹中,创建 index.js 文件并输入以下内容:
const images = {
main_bg: require('./background.png'),
main_logo: require('./auth/home_title.png'),
///you can add more many images like this here.
};
module.exports = images;
Run Code Online (Sandbox Code Playgroud)
使用图像时,您可以这样做:
从“../../assets/index”导入图像;...
| 归档时间: |
|
| 查看次数: |
25041 次 |
| 最近记录: |