reactjs - TypeError:无法读取未定义反应的属性“url”
问题描述
有人可以帮忙吗?我得到了文件 AddPost.js
</div>
{this.props.admin.post.PostImage ?
<img src={API.makeFileURL(this.props.admin.post.PostImage[0].url, this.props.auth.token)} className="post-image" />
: null}
<div>
<Button
variant="contained"
color="primary"
onClick={e => {
$('.MyFile').trigger('click');
}}
><ImageIcon />Upload Post Image</Button>
<input type="file" style={{display: 'none'}} className="MyFile" onChange={this.uploadImage}/>
</div>
API 文件包含此功能:
makeFileURL: (url, token) => {
return host + url + "?access_token" + token;
}
解决方案
import {Link,Route} from 'react-router-dom';
export const Category = ({match}) => {
return (
<div>
<ul>
<li><Link to={`${match.url}/mobile`} >Mobile</Link></li>
<li><Link to={`${match.url}/laptop`} >Laptop</Link></li>
<li><Link to={`${match.url}/shoes`} >Shoes</Link></li>
</ul>
</div>
)
}
在这种情况下,任何人都会收到错误“TypeError:无法读取未定义的属性'url'”,因此需要更改
<Route path='/category' component={Category} />
推荐阅读
- java - 使用签名链接的 S3 大文件上传
- docker - Windows 10 docker-compose 占用 100% 磁盘使用率
- powershell - PowerShell 将托管属性映射到已爬网属性
- cordova - 使用 Cordova CLI 3.6 安装 Cordova 最新版本?
- c# - 如何在 Xamrin Android 应用程序中使用 ASMX soap?
- matlab - 使用 radiomics 包的输入参数不足
- stream - 创建自定义标准输出流
- c# - Entity Framework Code First 对象类中字节数组属性的替代方案?
- tensorflow - 如何使用 tensorboard 分析 keras 预测调用
- javascript - 与 DOM 事件相比,rxjs Observable 有哪些优势?