简体   繁体   English

图片不显示 React native Expo

[英]Image not Showing React native Expo

React Native Code反应本机代码

<View style={styles.container}>
      <View style={styles.carlist}>
        {api.map((item, key) => (
          <View key={item.brand} style={styles.photo}>
            <Text>{item.brand}</Text>
            <Image source={{ uri: item.logo }} />
          </View>
        ))}
      </View>
    </View>

JSON file Data JSON 文件数据

    {
    "brand": "Volvo",
    "logo":"https://1drv.ms/u/s!AiyE3dAIjI8lgRtQot0nBaNTeCLb?e=O2r7fz",
    "models" :[
        {
            "name":"XC90",
            "link":"https://1drv.ms/u/s!AiyE3dAIjI8lgV6XcQOmso1W2rta?e=wXTM4d"
        },
        {
            "name":"XC60",
            "link":"https://1drv.ms/u/s!AiyE3dAIjI8lgWjRXFT6G9NEzbS4?e=ELJ4HZ"
        },
        }

The URL is supplied correctly but the image does not appear on the screen. URL 已正确提供,但图像未出现在屏幕上。 Images are stored in one drive.图像存储在一个驱动器中。 I have tried with images on the inte.net as well but none of those appear on the screen.我也尝试过使用 inte.net 上的图像,但没有一个出现在屏幕上。 I want to take JSON data and display it in grid form if any content that helps with that would be helpful as well.我想获取 JSON 数据并以网格形式显示它,如果任何有助于此的内容也有帮助的话。 Expo Documentation shows it to be like this but in loop it does not appear. Expo 文档显示它是这样的,但在循环中它没有出现。

The image you are trying to load needs an Authorization .您尝试加载的image需要Authorization Yes, it will show up if you paste the URL in the browser but for the Image component you need some kind of Authorization from OneDrive.是的,如果您将 URL 粘贴到浏览器中,它就会显示出来,但是对于Image组件,您需要 OneDrive 的某种Authorization That's the reason it's not loading.这就是它没有加载的原因。

Read More about Image Headershere 在此处阅读有关图像标题的更多信息

And also make sure you provide Dimensions to the images in order to show them.还要确保为图像提供尺寸以显示它们。 As mentioned in the docs here , Unlike with static resources, you will need to manually specify the dimensions of your image.正如此处文档中所述,与静态资源不同,您需要手动指定图像的尺寸。

For Example -例如 -

<Image source={{ uri: SomeURI }} />
// This will not load and the image would not be shown.
<Image source={{ uri: SomeURI }} style={{ width: 100, height: 100 }} />
// This will load perfectly and the image will be shown.

Working Example Here这里的工作示例

you should add header 'accept':你应该添加 header '接受':

<Image source={{ uri: userInfo.picture, headers: { 'Accept': 'image/*'} }} style={styles.profilePic} />

as shown indocs文档所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM