用strapi显示图像和反应
我开始对Strapi进行反应,但无法正确显示图像。
我的“动物”集合具有一个“图像”字段,用于显示图像。
但是,我无法显示图像(即将上传)
,实际上我无法显示图像中的数据,
这要归功于所有会帮助我
import { useEffect, useState } from 'react';
import axios from 'axios'
function AnimauxListe() {
const [error, setError] = useState(null);
const [Animaux, setAnimaux] = useState([]);
const api_url = "http://localhost:1337/"
useEffect(() => {
axios
.get('http://localhost:1337/api/animaux?populate=*')
.then(({ data }) => setAnimaux(data.data))
.catch((error) => setError(error))
}, [])
if (error) {
// Print errors if any
return <div>An error occured: {error.message}</div>;
}
return (
<div className="App">
<h2> Affichage des animaux présents dans la base de données</h2>
<ul>
{Animaux.map(animal =>
<div key="animal.attributes.id" className="card" >
<img src={animal.attributes.image.url}
className="card-img-top" alt="raté"/>
<div className="card-body">
<h5 className="card-title">{animal.attributes.image.url}{animal.attributes.nom}</h5>
<p className="card-text">{animal.attributes.Description}</p>
<p>{animal.attributes.image.url}</p>
<a href="#" className="btn btn-primary">Voir {animal.attributes.nom}</a>
</div> </div>
)}
</ul>
</div>
)
}
使用代码的人,我只是想检索URL目前的图像,但不可能。通过所有更新,我找不到将我的问题与解决问题的解决方案相匹配的主题。 谢谢
I'm starting react with strapi and I can't display an image correctly.
My "animals" collection has an "image" field which is used to display an image.
However, I can't display the image (which is in upload)
In fact, I can't display the data that is in the image
Thanks to everyone who will help me
import { useEffect, useState } from 'react';
import axios from 'axios'
function AnimauxListe() {
const [error, setError] = useState(null);
const [Animaux, setAnimaux] = useState([]);
const api_url = "http://localhost:1337/"
useEffect(() => {
axios
.get('http://localhost:1337/api/animaux?populate=*')
.then(({ data }) => setAnimaux(data.data))
.catch((error) => setError(error))
}, [])
if (error) {
// Print errors if any
return <div>An error occured: {error.message}</div>;
}
return (
<div className="App">
<h2> Affichage des animaux présents dans la base de données</h2>
<ul>
{Animaux.map(animal =>
<div key="animal.attributes.id" className="card" >
<img src={animal.attributes.image.url}
className="card-img-top" alt="raté"/>
<div className="card-body">
<h5 className="card-title">{animal.attributes.image.url}{animal.attributes.nom}</h5>
<p className="card-text">{animal.attributes.Description}</p>
<p>{animal.attributes.image.url}</p>
<a href="#" className="btn btn-primary">Voir {animal.attributes.nom}</a>
</div> </div>
)}
</ul>
</div>
)
}
On my code, I'm just trying to retrieve the url of the image for the moment but impossible. With all the updates I can't find a topic that matches my problem with a solution that fixes it.
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
用这条线替换这条线
try to replace this line
with this line