Warning:Failed prop type: Invalid prop 'source' supplied to 'Image' in Image



  • Warning:Failed prop type: Invalid prop 'source' supplied to 'Image' in Image只要写Image标签就报这种警告是为什么



  • Image组件有没有指定source?



  • import React, {Component} from 'react';
    import TabNavigator from 'react-native-tab-navigator';
    import {Platform,
    StyleSheet,
    Text,
    View,
    Image,
    ImageBackground,
    ScrollView,
    TouchableOpacity,
    Alert} from 'react-native';
    import {screenH, screenW, scaleSize, setSpText} from '../../../common/ScreenUtil';
    import PersonalCenter from './mine/PersonalCenter';
    type Props = {};
    type State = {
    };
    export default class Mine extends Component<Props, State> {
    _onPressButton() {
    Alert.alert('You tapped the button!');
    }

    state = {

    }

    componentDidMount() {

    }

    render() {
    return (

        <View style={styles.backgroundImage}>
          <ImageBackground source={require('../../../../res/images/mine/mine_bg.png')} style={{width: '100%', height: '100%'}}>
            <View style={styles.userMessage} >
              <View>
                <Text style={{ fontSize: setSpText(31),color: 'white'}}>昵称就是要长</Text>
                <Text style={{fontSize: setSpText(18),color: 'white',marginTop: scaleSize(10)}}>ID:123456</Text>
                <View style={{flexDirection: 'row',marginTop: scaleSize(5),alignItems: 'center'}}>
                  <Text style={{fontSize: setSpText(15),color: 'white'}}>普通会员</Text>
                  <Image style={{marginLeft: scaleSize(7.5),marginTop: scaleSize(2)}} source={require('../../../../res/images/mine/arrow_white.png')}/>
                </View>
    
              </View>
              <View style={styles.userImg} >
                <Image style={{flex: 1, alignItems: 'center', justifyContent: 'center', width: null, height: null, resinzeMode: Image.resizeMode.stretch}} source={require('../../../../res/images/mine/mine_task_type_3.png')}/>
              </View>
            </View>
          </ImageBackground>
    

    </View>

    代码如上,不知道为啥,求解谢谢



  • 看你这个路径感觉会超出项目目录
    RN不能引用任何超出项目目录的文件



  • @晴明 图片是可以出来的,但是就是会一直报警告在安卓上面



  • 我试着模拟一下你的代码,可没出现警告,也许你应该查一查其他地方的image组件引用。


Log in to reply