【问题标题】:React - native .I can't import images, says it's not present on the wayReact - native .I can't import images,说它在路上不存在
【发布时间】:2023-04-07 03:14:02
【问题描述】:

当我尝试导入除 .js 扩展名之外的任何文件时,它会提示我找不到该文件。我现在正在尝试导入图像。自动完成不会找到图像,但会找到文件夹。如果我手动输入图像的名称,则会在制作捆绑包时出错。

版本 react-native 0.60.

enter image description here

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    如果你想这样使用它,你可以在你的图像文件夹中添加一个index.js 文件来导出你的所有图像,如下所示:

    images/index.js

    import login from './ImageLogin.jpg';
    
    export default { login };
    

    login.js

    import images from '../images';
    

    然后

    <Image source={images.login}/>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-12
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2017-10-17
    • 2018-06-05
    相关资源
    最近更新 更多