React Native Image错误Failed prop type:提供给ForwardRef的无效prop源(Image)

问题描述 投票:1回答:1

在我的react-native应用程序中,我有一个包含Image组件的组件数组,但是我有这个错误

警告:失败的道具类型:提供给ForwardRef(图像)的无效道具源。

文件CampaignPreview

render() {
    return (
        <TouchableOpacity>
            <ImageBackground
                source={ require(this.props.imageFilePath) }
            >
            </ImageBackground>
        </TouchableOpacity>
    );
}

文件主页

render() {
    let campaigns = [
        {
            id: 1,
            name: "WildFit",
            expire: 1868029014,
            picFrame: "../assets/picture.jpg",
            done: 0.75
        }
    ];

    let campaignViews = campaigns.map( c => {
        return (
            <CampaignPreview
                imageFilePath={ c.picFrame }
                name={ c.name }
                completation={ c.done }
                key={ c.id }
            />              
        );
    });

    let view = (
        <View>
            <ScrollView>
                { campaignViews }
            </ScrollView>
        </View>
        );

    return view;
}

但如果我把字符串而不是this.props.imageFilePath它工作

image react-native react-props imagesource
1个回答
0
投票

我似乎'require(var)'在本地反应中是不可能的,我永远使用require('location'),你可以尝试将字符串保存在变量中。

要求只接受文字字符串

react native use variable for image file

© www.soinside.com 2019 - 2024. All rights reserved.