javascript - 绝对 url 不能放在点运算符之前反应
问题描述
我在反应中创建了一个应用程序。但是图像没有渲染。图像的json响应是
“缩略图”:“/wcsstore/ExtendedSitesCatalogAssetStore/images/catalog/apparel/girls/gsh020_shoes/200x310/gsh020_2001.jpg”
我在代码中实现的内容如下。
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import axios from 'axios';
class PLPMenu extends Component {
state = {
shoeCategory: []
}
componentDidMount() {
const url = 'GirlShoeCategory'
axios.get(`http://localhost:3030/${url}`)
.then(res => {
console.log(res.data.express.catalogEntryView);
this.setState({
shoeCategory: res.data.express.catalogEntryView
})
})
}
render() {
const { shoeCategory } = this.state;
const picUrl = 'https://149.129.128.3:8443'
return (
<div>
<div className="container">
<div className="row">
{
shoeCategory.map(shoeList => (
<div className="col-md-4">
<h2 key={shoeList.uniqueID}></h2>
<img src={shoeList + picUrl + .thumbnail}/>
<Link to="/PDP"><p className="pdp">{shoeList.name}</p></Link>
<p>{shoeList.price[0].value}</p>
</div>
))
}
</div>
</div>
</div>
)
}
}
export default PLPMenu;
在上面的代码中,在map函数下,我实现了{shoeList.thumbnail}。但是,图像没有渲染。它需要在我无法实现的缩略图之前添加绝对路径。有人可以帮助我如何连接它。
解决方案
我不完全确定我是否正确理解您,但您可以使用模板字符串进行连接。
例如:
const imageSrc = `${picUrl}${shoeList}${shoeList.thumbnail}`
希望这可以帮助你。
干杯
推荐阅读
- ios - Mapbox 的 ClusterKit 无法正常工作?
- python - 如何创建基于 txt 文件中存储的到期日期打印上个月的计算
- android - 未调用 RemoteViewsService onGetViewFactory
- arrays - 在 C++ 中对变体的 OLE SafeArray 进行排序
- node.js - 可以将异步函数作为 Websocket(ws) 侦听器传递吗?(node.js 和 ws 库)
- java - javafx线程限制为32?
- c - 如何正确修改以下“switch”语句以获得预期的输出值
- asp.net-web-api - 如何允许使用 IIS Express 和 Web API 的 DELETE 方法?
- performance - 在 i7 上访问“原始”寄存器时是否存在瓶颈?
- spring-boot - @PropertySource 不会自动将 String 属性绑定到枚举?