gpt4 book ai didi

reactjs - 在 Material-UI CardMedia 中显示加载器

转载 作者:行者123 更新时间:2023-12-04 15:58:29 26 4
gpt4 key购买 nike

当图像尚未加载但它不工作时,我试图在 CardMedia 中显示加载器。如果我将加载器放在 CardText 中,那么页面会正常工作并显示加载器。我的代码有什么问题,或者是否有在图像加载之前在卡片媒体中显示加载程序的解决方案?

Screenshot for your ref

我使用的是 material-ui v0 版本。

这是我的代码

加载程序:

renderLoading(){
return (
<RefreshIndicator
size={40}
left={10}
top={0}
status="loading"
style={{marginLeft: '50%', display: 'inline-block', position: 'relative'}}
/>
)
}

卡片:

<CardMedia overlay={<CardTitle title={this.props.userName} subtitle="Your cover photo" />}>
{this.props.coverPhotoLoading && this.renderLoading()} //this isn't working
{coverPhoto ? <img src={coverPhoto} width="100%" height="400px"/> :
<img src="" alt="This user cover photo is not set" width="100%" height="400px"/>}

</CardMedia>

最佳答案

发生这种情况的原因是因为您试图同时显示 <RefreshIndicator />和一个空的 <img/>同时。

考虑执行以下操作:

<CardMedia overlay={<CardTitle title={this.props.userName} subtitle="Your cover photo" />}>
{!this.props.coverPhotoLoading && coverPhoto ?
<img src={coverPhoto} width="100%" height="400px"/> :
this.renderLoading()}
</CardMedia>

关于reactjs - 在 Material-UI CardMedia 中显示加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51052799/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com