【问题标题】:Failed prop type: Invalid prop `source` supplied to `Image`道具类型失败:提供给“图片”的道具“来源”无效
【发布时间】:2021-06-22 19:52:46
【问题描述】:

我尝试从 api 获取 URI 图像,但它抛出了以下错误:

我一直在寻找这些信息,但找不到像我这样的案例

它不显示图像,但如果它传递数据

这是我的 api:

{
    "Home": [
        { "id": "1",
            "LinkHome":"https://telesistema11.com.do/tn-deportes/futbol/la-quinta-jornada-de-la-ldf-iniciara-este-proximo-jueves",
            "URLHome":"{uri: 'https://telesistema11.com.do/storage/app/uploads/public/609/b45/eab/thumb_46456_932_582_0_0_crop.jpeg'}"
        }
    ],
    
    "TSTA": [
        { "id": "1",     
            "LinkTSTA":"",
            "URLTSTA":""
        }
    ],
            

    "Radio": [
        { "id": "1", 
            "LinkRadio":"",
            "URLRadio":""
        }
    ]
    
}

这是我的代码:

    function Getdatajson(){
  const [isLoading, setLoading] = useState(true);
  const [data, setData] = useState([]);

  useEffect(() => {
    fetch('http://72.44.48.164/wp-content/themes/tn/json/PublicidadTeleStream.json')
      .then((response) => response.json())
      .then((json) => setData(json.Home))
      .catch((error) => console.error(error))
      .finally(() => setLoading(false));
  }, []);

  return (
    <View style ={styles.bannerHome}>
      {isLoading ? <ActivityIndicator/> : (
        <FlatList
          data={data}
          keyExtractor={({ id }, index) => id}
          renderItem={({ item }) => (
            <TouchableOpacity style={{backgroundColor:'red'}} onPress={()=>
              Linking.openURL("item.LinkHome")
            }>
              <Image
                style={styles.imgad}
                source={item.URLHome}
              />
            </TouchableOpacity>
          )}
        />
      )}
    </View>
  )
}

我是新手反应原生,所以我不知道问题是什么 请问我需要帮助。

【问题讨论】:

  • 请不要在图片中发布代码。请编辑问题并提供基于文本的minimal reproducible example
  • 这意味着您将 source={item.URLHome} 传递给 Image 组件,这不是一个有效的道具。 Image 组件的实现在哪里?确保您的 Image 组件作为该道具。
  • URLHome 应该是 Object { uri: 'https://telesistema11.com.do/storage/app/uploads/public/609/b45/eab/thumb_46456_932_582_0_0_crop.jpeg' } 而不是 String 值
  • 你好,我已经进行了更改并且工作正常,但是当我生成 apk 时,它没有显示我从 Json 带来的图像。你知道这可能是什么吗? @JimboMagusib
  • 这可能有很多原因。如果 ios 存在可以通过 npx react-native-fix-image 修复的问题,或者它可能是源 URI 标头或样式。

标签: javascript json react-native jsx


【解决方案1】:

我用 temp 修复了它 const temp = item.URLHome 来源={item.URLHome}

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-28
相关资源
最近更新 更多