【问题标题】:Display image with react from strapi显示带有来自strapi的反应的图像
【发布时间】:2021-08-24 17:47:43
【问题描述】:

我在从strapi 获取图像时遇到问题。 我尝试了很多,但它不会显示任何图像,当我发布富文本广告时尝试图像它不会工作,有人可以帮助我!

const ApiUrl = ('http://localhost:1337')

const { id } = useParams() const {loading , error , data } = useFetch('http://localhost:1337/reviews/ ' + id)

if(loading) return <p>Loading..</p>
if(error) return <p>Error</p>

return (
    <div className={classes.root}>
      <div className={classes.container}>
     
      <img src={ApiUrl + data.image} alt={data.naam} />
      <h2 className={classes.headertxt}>{data.naam}</h2> 

也试过 {review.image} {data.image.url} review.image.url

问候

【问题讨论】:

    标签: javascript reactjs image fetch strapi


    【解决方案1】:

    我认为您需要检查您的 API(如果您使用 rest API)或 GraphQl Playground 的架构(如果您使用 GrapQl)的文档。

    安装 Swagger UI 文档插件以检查架构。

    这可能会解决您的问题。

    【讨论】:

      【解决方案2】:

      也许这可以给你一些方向。

      LINK TO STRAPI CONTENT API GET

      这就是它应该为您返回的:

      {
            "id": 1,
            "title": "Restaurant 1",
            "cover": {
              "id": 1,
              "name": "image.png",
              "hash": "123456712DHZAUD81UDZQDAZ",
              "sha256": "v",
              "ext": ".png",
              "mime": "image/png",
              "size": 122.95,
              "url": "http://localhost:1337/uploads/123456712DHZAUD81UDZQDAZ.png",
              "provider": "local",
              "provider_metadata": null,
              "created_at": "2019-12-09T00:00:00.000Z",
              "updated_at": "2019-12-09T00:00:00.000Z"
            },
            "content": [
              {
                "__component": "content.title-with-subtitle",
                "id": 1,
                "title": "Restaurant 1 title",
                "subTitle": "Cozy restaurant in the valley"
              },
              {
                "__component": "content.image-with-description",
                "id": 1,
                "image": {
                  "id": 1,
                  "name": "image.png",
                  "hash": "123456712DHZAUD81UDZQDAZ",
                  "sha256": "v",
                  "ext": ".png",
                  "mime": "image/png",
                  "size": 122.95,
                  "url": "http://localhost:1337/uploads/123456712DHZAUD81UDZQDAZ.png",
                  "provider": "local",
                  "provider_metadata": null,
                  "created_at": "2019-12-09T00:00:00.000Z",
                  "updated_at": "2019-12-09T00:00:00.000Z"
                },
                "title": "Amazing photography",
                "description": "This is an amazing photography taken..."
              }
            ],
            "opening_hours": [
              {
                "id": 1,
                "day_interval": "Tue - Sat",
                "opening_hour": "7:30 PM",
                "closing_hour": "10:00 PM"
              }
            ]
          }
      

      【讨论】:

      • 感谢您的回复,根据您给我的信息,我尝试了 review.foto.formats.thumbnail.url 并且应该显示它,但我仍然没有看到图像出现,因为我尝试了所有其中,我想我错过了什么,
      • @cendrickking 也许你可以为你的 img 标签添加一些宽度和高度 ` ` 类似的,你试过吗?
      • 是的也没用,我现在已经安装了文档 api,并尝试了很多东西,当我找到它时告诉它
      • 如果你把你的codesandbox.io放在这里,我们可以提供更多帮助
      猜你喜欢
      • 2021-08-03
      • 2022-06-28
      • 2021-03-15
      • 2021-06-29
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 2022-01-14
      • 1970-01-01
      相关资源
      最近更新 更多