【问题标题】:React native: importing Images not working反应原生:导入图像不起作用
【发布时间】:2023-03-11 14:49:01
【问题描述】:

我无法将图像导入我的组件。我将图像保存在一个名为 WidgetImages 的文件中,并在 Images.js 中编写了这段代码来导入它:

var Images = {
    Weather: require('./WidgetsImages/Weather.png'),
    News: require('./WidgetsImages/News.png'),
    AgendaWidget: require('./WidgetsImages/AgendaWidget.png'),
    SpotifyPlayer: require('./WidgetsImages/SpotifyPlayer.png'),
    VoiceReader: require('./WidgetsImages/VoiceReader.png'),
    Clock: require('./WidgetsImages/Clock.png'),
};

export default Images;

然后在我的组件文件中,我有以下内容:

import Images from '../assets/Images';
// code here ... 
<Image source={Images.item} />

我不知道问题出在哪里。我查看了以前的问题,我的结构相同,我的导入是正确的。那么这里似乎有什么问题呢?

【问题讨论】:

    标签: javascript image react-native


    【解决方案1】:

    您能否解决您遇到的错误? 根据您粘贴的代码,&lt;Image source={Images.item} /&gt; 行必须如下

    
    <Image source={Images.Weather} />
    // item should me replaced by the actual properties of the Images object
    
    

    【讨论】:

      猜你喜欢
      • 2021-08-23
      • 2021-10-05
      • 2018-11-04
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 2020-02-04
      • 2018-01-02
      • 1970-01-01
      相关资源
      最近更新 更多