我遇到了多个与内联样式背景图像相关的警告。使用 React-static,我没有任何问题,但现在使用 Gatsby我收到此错误:
warning Unexpected string concatenation of literals
如果我只想使用内联样式,我该如何编写代码?
现在,我正在导入背景图片并使用内联样式。我宁愿导入图像并使用内联样式,也不愿创建多个 CSS 样式。
代码:
import Background from '../img/background.gif';
<div id="hero" className="header-banner" style={{background: 'url(' + `${Background}` + ')'}}></div>
最佳答案
看起来您已经在评论中弄明白了,这只是一个引用信息:您看到的消息来自 ESLint , 具体来说 this rule .
This rule aims to flag the concatenation of 2 literals when they could be combined into a single literal. Literals can be strings or template literals.
所以你的代码是有效的。这要么是 Gatsby 的默认 ESLint 设置,要么是您自己的设置对它很挑剔。如果您不喜欢该规则,可以通过 setting up your own ESLint setting 将其删除.
关于css - 消息 "warning Unexpected string concatenation of literals",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55108227/