【问题标题】:React Native - Loading local image in ImageReact Native - 在 Image 中加载本地图像
【发布时间】:2017-07-21 20:11:59
【问题描述】:

我使用实际的 React Native 并尝试在应用程序的 Caches 文件夹(在 iOS 模拟器上)中显示由 react-native-fs 加载和保存的文件的图像 在我的组件的 render 方法中,我使用了这个:

let logoPath = '/Users/emerkushev/Library/Developer/CoreSimulator/Devices/33E9E1E9-70EF-4DCF-AAC7-AD194F567F14/data/Containers/Data/Application/AEA3B326-EF82-418F-915F-9657E0DEE3DE/Library/Caches/111709.102.logo.png'
...
<Image source={{uri: logoPath}} style={{width: 300, height: 300}} />

它会在调试控制台中生成错误消息:

Image is not defined
    handleException @   ExceptionsManager.js:63
    handleError @   InitializeCore.js:114
    reportFatalError    @   error-guard.js:44
    guard   @   MessageQueue.js:48
    callFunctionReturnFlushedQueue  @   MessageQueue.js:107
    (anonymous) @   debuggerWorker.js:71

ExceptionsManager.js:71 Unhandled JS Exception: Image is not defined
    reactConsoleErrorHandler    @   ExceptionsManager.js:71
    console.error   @   YellowBox.js:61
    logIfNoNativeHook   @   RCTLog.js:38
    __callFunction  @   MessageQueue.js:236
    (anonymous) @   MessageQueue.js:108
    guard   @   MessageQueue.js:46
    callFunctionReturnFlushedQueue  @   MessageQueue.js:107
    (anonymous) @   debuggerWorker.js:71

需要如何正确显示这种类型的图像文件? 我还尝试将file:// 添加到logoPath,但结果相同。

【问题讨论】:

    标签: ios image react-native


    【解决方案1】:

    真丢脸:我只是忘记添加import {Image} from 'react-native'

    【讨论】:

    • :/ Image is not defined
    • 是的,我阅读并理解为“图像文件未定义”。
    • 好吧,谢谢哥们,被同样愚蠢的错误困住了。我。
    【解决方案2】:

    我推荐你require这样的图片:

    logoPath = require('/Users/emerkushev/Library/Developer/CoreSimulator/Devices/33E9E1E9-70EF-4DCF-AAC7-AD194F567F14/data/Containers/Data/Application/AEA3B326-EF82-418F-915F-9657E0DEE3DE/Library/Caches/111709.102.logo.png');
    <Image source={logoPath} />
    

    为什么?因为this

    【讨论】:

      猜你喜欢
      • 2015-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多