Image React-native not working

不问归期 提交于 2019-11-28 09:50:04

问题


Iam trying to do this:

<Image
  style={styles.image}
  source={require(`./img/${params.image}.png`)}
/>

but returns me this error: "Unknown named module"


回答1:


I have also faced this issue, you can not call image like

source={require(`./img/${params.image}.png`)}

you have to use another variable to store path and then call it (including require)

For example:

let imagePath = require("../../assets/list.png");

Also note that you can not call variable into require.

check this ref. url: https://github.com/facebook/react-native/issues/2481




回答2:


Try importing your image at top like this:

import React, { Component } from "react";
import bgimg from "./assets/bg.jpg";

Then you can use it like this:

<Image source={bgimg}>

If this doesn't work, can you please share the directory structure, please show the location of the file you are doing the require and the location of this image in the directory structure.



来源:https://stackoverflow.com/questions/44468500/image-react-native-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!