Reactjs 如何使用React.js中从数据库检索的图像路径显示图像
我正在尝试使用api axios显示图像,api正在从数据库检索路径图像,但图像未加载Reactjs 如何使用React.js中从数据库检索的图像路径显示图像,reactjs,laravel,image,api,axios,Reactjs,Laravel,Image,Api,Axios,我正在尝试使用api axios显示图像,api正在从数据库检索路径图像,但图像未加载 import axios from 'axios'; 类产品扩展组件{ state={ products:[], }; componentDidMount() { axios.get(`http://localhost/CraveByMarwa/public/api/products`) .then(res => { const products
import axios from 'axios';
类产品扩展组件{
state={
products:[],
};
componentDidMount() {
axios.get(`http://localhost/CraveByMarwa/public/api/products`)
.then(res => {
const products = res.data;
this.setState({ products });
})
}
render() {
return (
<div>
<div className="block-section big-spacer">
<div className="container">
<h3 className="section-title" data-aos="fade-up" style={{fontSize: 55, textAlign: 'center'}}>
<span style={{color: 'rgba(209, 0, 0, 1)'}}>Plans & Pricing
</span>
</h3>
</div>
<div className="container">
<div className="row">
{ this.state.products.map(products =>
<div className="col-md-4">
<div className="block-img">
<div className="flip-card">
<div className="flip-card-inner">
<div className="flip-card-front">
<img src={products.productImagePath} alt={products.title} style={{width: 300, height: 500}} />
状态={
产品:[],
};
componentDidMount(){
axios.get(`http://localhost/CraveByMarwa/public/api/products`)
。然后(res=>{
常数产品=分辨率数据;
this.setState({products});
})
}
render(){
返回(
计划与定价
{this.state.products.map(products=>
我找到了一个解决方案,可以在公用文件夹中创建一个图像文件,并将路径添加到数据库中,例如:数据库将类似于“image/123.png”您好,欢迎使用SO。您可以通过控制台记录并显示products.productImagePath中的内容吗?它是服务器中图像文件的路径还是blob,还是生成的url?@Darkshadow它的显示例如:productImagePath:“./css/image/thestandard.png”@Darkshadow有什么想法吗?提前谢谢。