React Native-无法从路径导入图像

我有以下基本的反应本机代码:

enter image description here

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

//images
import login_blueGirl from './assets/images/login_blueGirl.png';


const App = () => {
  return (
    <>
     <View style={styles.container}>
        <Image source={login_blueGirl}></Image>
     </View>
    </>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'column'
  }
});

export default App;

I'm getting a Cannot find module './assets/images/login_blueGirl.png'. When I type ./ VSCode give me however the autocomplete option:

enter image description here enter image description here

为什么会这样呢?

评论
  • 囍
    回复

    That's not quite how you're supposed to be importing images, use require instead.

    const App = () => {
        return (
            <View style={styles.container}>
                <Image source={require("./assets/images/login_blueGirl.png")} />
            </View>
        );
    };