在我的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
它工作
我似乎'require(var)'在本地反应中是不可能的,我永远使用require('location'),你可以尝试将字符串保存在变量中。
要求只接受文字字符串