【问题标题】:ReactJs set background imageReactJs 设置背景图片
【发布时间】: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 same unresolved` 错误

标签: reactjs


【解决方案1】:

无论如何,我完全错过了我当前的component 超出或范围的观点。 这修复了它../../static/images/auth_bg.jpg'

【讨论】:

    猜你喜欢
    • 2017-12-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2020-11-21
    • 2015-05-09
    • 2012-03-07
    • 2020-07-03
    • 2011-09-01
    相关资源
    最近更新 更多