【问题标题】:Local images now displaying React Native本地图像现在显示 React Native
【发布时间】:2020-09-08 01:05:57
【问题描述】:

我的本​​地图片突然停止在我的应用中显示。

我尝试了这里提出的解决方案:https://stackoverflow.com/questions/35354998/react-native-ios-app-not-showing-static-assets-images-after-deploying 但它没有用。

我正在按如下方式导入我的图像:

import image from '../../assets/images/home-1.jpg';
...
return (
      <SafeAreaView style={[styles.container, {margin: 0}]}>
        <Image source={image} style={styles.image} />
        ...
      </SafeAreaView>
    );
...
const styles = StyleSheet.create({
image: {
    backgroundColor: 'red',
    width: 300,
    height: 300,
  },
...

但我的图像看起来像这样:

有什么问题?

【问题讨论】:

    标签: react-native


    【解决方案1】:

    我认为你的使用是错误的。 你可以试试:

     <Image source={require('./my-icon.png')} />
    

    React-native 的文档中的更多信息。请关注。

    【讨论】:

    • 不,我尝试使用const image = require('../../assets/images/home-1.jpg');,但它仍然不起作用。奇怪的是它曾经可以工作。
    猜你喜欢
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多