简体   繁体   English

反应本地映像“无法解析模块”

[英]React native image “Unable to resolve module”

I'm trying to add a logo to my app, and I require the image from a folder inside the project's folder. 我正在尝试向我的应用添加徽标,并且我需要来自项目文件夹内文件夹的图像。 I followed the docs, and it won't recognize my logo image, I even tried with a different folder and still nothing. 我遵循了文档,但无法识别我的徽标图像,甚至尝试使用其他文件夹,但仍然没有任何操作。 "The module './logowo.png' could not be found" “找不到模块'./logowo.png'” 在此处输入图片说明

Any ideas? 有任何想法吗? Thank you! 谢谢!

try importing the image first? 尝试先导入图像?

For example: 例如:

At line 9: 在第9行:

import imagename from './logwo.png'

and the image tag: 和图片标签:

<Image source = { imagename } />

As by your error, "The module './logowo.png' could not be found" . 由于您的错误, “找不到模块'./logowo.png'” You might have mis spelled the name of your image instead of ./logwo.png . 您可能拼错了图片的名称,而不是./logwo.png The path you have mentioned is fine. 您提到的路径很好。 It works perfectly for me, when i try to mimic the error. 当我尝试模仿该错误时,它对我来说非常理想。 You may use it like below, 您可以按以下方式使用它,

import React, { Component } from 'react';
import { StyleSheet, Image, Text, View } from 'react-native';

export default class Logo extends Component{
  render(){
    return(
      <View style={styles.container}>
        <Image source={require('./logwo.png')} />
      </View>
    )
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM