EJS在style属性内部使用时出现错误 “Error: property value expected”。

huangapple go评论47阅读模式
英文:

EJS giving error "Error: property value expected" when used inside a style attribute

问题

我正在尝试根据服务器发送的颜色设置我的 div 的背景颜色。我无法使用类来解决这个问题,因为颜色值可以是任何合法的颜色值。然而,当我输入以下内容时,VSCode 给我一个错误。EJS 是否不允许与与 CSS 相关的内容一起使用?

<div style="background-color: <%= display_color %>;"></div> // 错误:需要属性值
英文:

I am trying to set a background color on my div based on a a color send down by my server. I can't solve this with classes because the color value could be any legal color value. However, VSCode is giving me an error when I type the following. Is EJS not allowed to use with css related stuff?

&lt;div style=&quot;background-color: &lt;%= display_color %&gt;;&quot;&gt;&lt;/div&gt; // Error: property value expected

答案1

得分: 1

这是一个 ESLint 错误。ESLint 是一个代码检查工具。它可以帮助你找到并修复(大多数/通常情况下)代码的风格问题。它高度可配置,还可以用于自动修复一些问题。

正如你已经发现的,你可以像这样禁用单个位置/行的代码检查警告:

&lt;div &lt;% /* eslint-disable css-propertyvalueexpected */ %&gt; style=&#39;background-color: &lt;%= display_color %&gt;;&#39;&gt;&lt;/div&gt;

如果你想要永久禁用这个警告,可以创建 ESLint 配置文件 并在那里进行配置。

如果你还没有安装 ESLint NPM 包 以便以这种方式使用它,那么你可能是因为你的 VS Code 扩展之一而遇到了这个问题。

英文:

This is an ESLint error. ESLint is a linting tool. It can help you find and fix (mostly/usually) stylistic problems with your code. It's highly configurable, and can also be used to auto-fix some problems for you.

As you already found, you can disable the lint warning for a single site/line like so:

&lt;div &lt;% /* eslint-disable css-propertyvalueexpected */ %&gt; style=&#39;background-color: &lt;%= display_color %&gt;;&#39;&gt;&lt;/div&gt;

If you want to disable the warning once and for all, create an ESLint configuration file and do it there.

If you haven't installed the ESLint NPM package to use it that way, you're probably getting this because of one of your VS Code extensions.

huangapple
  • 本文由 发表于 2023年2月14日 22:34:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75449342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定