【问题标题】:warning: Failed prop type: Invalid prop `source` supplied to `Image`. in react native警告:道具类型失败:提供给“图像”的道具“来源”无效。在本机反应
【发布时间】:2021-03-22 06:16:13
【问题描述】:

我是原生反应的新手。我创建了一个屏幕。我在其中添加了数字签名。当我拖动签名时,我将其图像保存在状态中。然后我在屏幕上显示这个状态图像。但我收到这样的错误=警告:失败的道具类型:无效的道具source提供给Image。请帮忙。这是代码

const[Image1, setImage1]= useState(null);

    const Image1 = result.pathName;
    console.log("Response = "+Image1);
    setImage1({Image1: Image1})

 <Image
                source={{uri : Image1}}
                style={{
                 width: '100%',
                 height: 200,
                 resizeMode: 'contain',
                 }} />

【问题讨论】:

    标签: javascript image react-native file-upload digital-signature


    【解决方案1】:

    useState 变量首字必须小写

    你不能使用相同的变量名, 如果您使用的是网络图像,那么您的图像组件应该是这样的,

    const[image, setImage]= useState(null);
    const [imagePath,setImagePath ] = useState(result.pathName);
    console.log("Response = "+imagePath);
    setImage(imagePath)
    
     <Image 
    source={{uri : image}}
    style={{
    width: '100%',
    height: 200,
    resizeMode: 'contain',
     }} 
    />
    

    如果你使用本地图像,那么你的图像组件是这样的,

    <Image 
    source={require(image)}
    style={{
    width: '100%',
    height: 200,
    resizeMode: 'contain',
     }} 
    />
    

    【讨论】:

    • 我得到了这样的共鸣 =。 /storage/emulated/0/saved_signature/signature.png。是图像吗。如果是图片那么为什么它没有显示在屏幕上
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    相关资源
    最近更新 更多