【问题标题】:Unable to resolve ../assets/image.png but i already install expo-asset on my project无法解析 ../assets/image.png 但我已经在我的项目上安装了 expo-asset
【发布时间】:2020-05-16 07:23:56
【问题描述】:

我正在尝试在资产中使用 Unable 图像,然后是 expo 预加载和缓存资产,但它显示此错误:

无法解析 ../assets/image.png

我已经在我的项目中安装了 expo-asset,并且我的图像已经以 JPG 和 PNG 的形式保留在资产中,但它仍然没有任何作用。

import React, { Component } from 'react';
import { StyleSheet, Text, View }  from 'react-native';
import firebase from 'firebase'
import { Asset } from 'expo-asset';
import { AppLoading } from 'expo';
import  MusicApp  from './App/index'; 

function cacheImages(images) {
        return images.map(image => {
          if (typeof image === 'string') {
            return Image.prefetch(image);
          } else {
            return Asset.fromModule(image).downloadAsync();
          }
        });   } export default class RegisterScreen extends Component {
        static navigationOptions = {
            header: null
        }
        constructor() {
            super();
            this.state = {
              isReady: false
            };
        }
        async _loadAssetsAsync() {
            const imageAssets = cacheImages([require('./assets/LUMO-logo.jpg')]);

            await Promise.all([...imageAssets]);
        }
        render(){
            if(!this.state.isReady){
                return(
                    <AppLoading
                            startAsync={this._loadAssetsAsync}
                            onFinish={() => this.setState({ isReady: true })}
                            onError={console.warn}
                    />
                );
            }
            return <MusicApp />;
        } } const styles = StyleSheet.create({
        container: {
          flex: 1,
          backgroundColor: '#fff',
          alignItems: 'center',
          justifyContent: 'center',
        },   
    });

谁能帮帮我。

【问题讨论】:

    标签: react-native png jpeg expo assets


    【解决方案1】:

    我不知道你在哪个文件中,所以你应该仔细检查你的图片是否与require(...)的路径匹配。

    小心'../../some/path/img.png''../some/path/img.png'

    【讨论】:

      猜你喜欢
      • 2020-01-20
      • 2019-12-28
      • 2022-06-12
      • 1970-01-01
      • 2019-12-16
      • 2019-10-10
      • 2020-02-06
      • 1970-01-01
      • 2017-05-14
      相关资源
      最近更新 更多