[英]Unable to load certain images after Build in ReactJS (served with github)
我正在尝试在 github 上启动我的网站。 运行npm run build
后,调用serve -s build
时一切都按预期加载。 但是,当托管在 github 上时,请参阅网站,我无法加载投资组合图像。 奇怪的是,我能够访问与每个项目关联的文件。
这是我的 ReactJS:
if(this.props.data){
var projects = this.props.data.projects.map(function(projects){
return <div key={projects.title} className="columns portfolio-item centreColumn">
<div className="item-wrap">
<a href={projects.url} target="_blank" rel="noreferrer noopener" title={projects.title}>
<img alt={projects.title} src={projects.image} />
<div className="overlay">
<div className="portfolio-item-meta">
<h5>{projects.title}</h5>
<p>{projects.category}</p>
</div>
</div>
<div className="link-icon"><i className="fa fa-link"></i></div>
</a>
</div>
</div>
})
}
和json:
"portfolio": {
"projects": [
{
"title": "Blah",
"category": "blah blah",
"image": "images/myImage.png",
"url": "https://example.com"
},
files
和images
存储在public folder
中。
我尝试过的几件事:
public
的根目录。../images/myImage.png
等。src={require(projects.image).default}
。任何建议都非常感谢 - 我迫不及待地想要启动并运行它!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.