首页 > 解决方案 > 使用 ImageBackground 时反应本机错误代码 500

问题描述

我正在学习本机反应,我的代码有错误

import React, {Component} from 'react';
import {View, ImageBackground, StyleSheet, Text} from 'react-native';

export default class Welcome extends Component{
    render() {
        return (
        <ImageBackground  source={require('./Image_app/welcome.jpg')}  style={styles.container} >
          <View style={styles.container}>
             <Text style={styles.headerText}>
               Setting background image in react native application
             </Text>
          </View>
        </ImageBackground>
        );
      }
    }

const styles = StyleSheet.create({
    container: {
    flex: 1,
    justifyContent: "center",
    alignItems: 'center',
    width: null,
    height: null,
    },
    headerText: {
    fontSize: 24,
    textAlign: "center",
    margin: 10,
    color: "white",
    fontWeight: "bold"
    }
});

并且此错误 在此处输入图像描述

在我的源中放置文件夹图像 在 此处输入图像描述

标签: react-native

解决方案


关闭捆绑器,删除您的node_modules,重新安装所有内容npm i,然后再次启动捆绑器。那应该可以解决您的问题。


推荐阅读