reactjs - 对话框 PaperProps 背景 url 不适用于本地路径
问题描述
我需要更改 Dialogs 的背景图像。我找到了覆盖 PaperProps 的解决方案。这是我使用的解决方案: React JS - 如何在对话框的 PaperProps 中添加样式(material-ui)
奇怪的是,如果我使用网站 url 没有问题。但是使用本地路径“../../images/image.png”会导致问题。我将使用带有 5 个不同页面的对话框,它们都将是不同的背景。
我尝试了很多不同的图像。
render() {
const {
fullScreen,
children,
showcaseText,
showcaseDescription,
noCloseButtonNeeded
} = this.props;
return (
<Dialog id="dialog-id"
PaperProps= {{
style: {
backgroundImage:'url("https://images.unsplash.com/photo-1515879218367-8466d910aaa4?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80")'
}
}}
fullScreen={fullScreen}
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='responsive-dialog-title'
>
<DialogTitle
onClose={this.handleClose}
noCloseButtonNeeded={noCloseButtonNeeded}
>
<img id="checkout-brand-desktop"
src={require('../../images/uAppLogo.png')}
height='30px'
width='130px'
alt={'logo'}
/>
<img id="checkout-brand-mobile"
src={require('../../images/NomadCardLogo-W@2x.png')}
height='30px'
width='130px'
alt={'logo'}
/>
</DialogTitle>
<div className='showcase'>
<h1 className='showcase__title'>{showcaseText}</h1>
<div className='showcase__description'>{showcaseDescription}</div>
{children}
</div>
</Dialog>
);
}
解决方案
我解决了我的问题;
PaperProps= {{
style: {
backgroundImage:'url("https://images.unsplash.com/photo-1515879218367-8466d910aaa4?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80")'
}
}}
fullScreen={fullScreen}
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='my own labels'
>
我像 id 一样使用 aria-labelledby。我创建了自己的标签,然后在我的 scss 文件中使用了这个标签。
div[aria-labelledby="my labels"]{
background-image:url("#")
}
推荐阅读
- postgresql - 根据最近的时间戳加入同一个表
- maven - Bamboo 无法在命令行中运行/读取带引号或双引号的 Maven 参数
- sql-server - 在可用报表生成器数据集中添加新数据点(变量)时矩阵的行数
- php - 在php中从单行的2列中获取值
- django - 用于移动应用程序的 Angular Web 应用程序代码库?
- c++ - 访问派生结构向量中的元素?
- spring-boot - 如何在使用 SpringBoot 应用程序的 RabbitMQ 连接错误后建立连接
- angular - 如何触发一个组件的更改。从另一个组件 Angular
- java - PSQLException 的无法到达的 catch 块。从 try 语句体中永远不会抛出此异常
- cypress - 赛普拉斯:如何滚动下拉列表以查找项目