【发布时间】:2020-05-25 23:23:08
【问题描述】:
无法正确设置bg 图像。
这是我尝试过的。
backgroundImage: 'url(./static/images/auth_bg.jpg)'
-
import Background from './static/images/auth_bg.jpg';backgroundImage: 'url(${Background})'
样式
const useStyles = makeStyles((theme) => ({
bg: {
backgroundImage: 'url(${Background})'
}
}));
const classes = useStyles();
<div className={classes.bg}>
我回来了
找不到模块:无法解析“./static/images/auth_bg.jpg” '/home/h1dd3n/Desktop/Folder/social_blog/blog_react/src/authentication/components'
除此之外,Background 是未使用的导入。下一行抱怨它无法解析目录static
【问题讨论】:
-
很好背景没有使用,因为您需要使用反引号(`)来呈现字符串中的变量并且您使用的是单引号
-
@buzatto 将其更改为 backsticks,仍然有相同的错误。而不是给 div 一个
className, i've tried giving it a styles property. Still sameunresolved` 错误
标签: reactjs