Skip to content

vue/script-indent

强制 <script> 中的一致缩进

  • 🔧 command line 上的 --fix 选项可以自动修复此规则报告的一些问题。

📖 规则详情

此规则强制在 <script> 中使用一致的缩进样式。默认样式为 2 个空格。

¥This rule enforces a consistent indentation style in <script>. The default style is 2 spaces.

Now loading...

🔧选项

¥🔧 Options

此规则有一些选项。

¥This rule has some options.

json
{
  "vue/script-indent": ["error", TYPE, {
    "baseIndent": 0,
    "switchCase": 0,
    "ignores": []
  }]
}
  • TYPE (number | "tab") ...缩进类型。默认值为 2。如果这是一个数字,则它表示一次缩进的空格数。如果这是 "tab",则它使用一个制表符进行一次缩进。

    ¥TYPE (number | "tab") ... The type of indentation. Default is 2. If this is a number, it's the number of spaces for one indent. If this is "tab", it uses one tab for one indent.

  • baseIndent (integer) ...顶层语句的缩进乘数。默认值为 0

    ¥baseIndent (integer) ... The multiplier of indentation for top-level statements. Default is 0.

  • switchCase (integer) ...case/default 子句的缩进乘数。默认值为 0

    ¥switchCase (integer) ... The multiplier of indentation for case/default clauses. Default is 0.

  • ignores (string[]) ...忽略节点的选择器。AST 规范是 此处。你可以使用 esquery 来选择节点。默认值为空数组。

    ¥ignores (string[]) ... The selector to ignore nodes. The AST spec is here. You can use esquery to select nodes. Default is an empty array.

注意

此规则仅检查 .vue 文件,不会干扰其他 .js 文件。不幸的是,默认的 indent 规则在打开时会尝试对两者进行 lint,因此为了使它们互补,你可以使用 overrides 设置并在 .vue 文件上禁用 indent 规则:

¥This rule only checks .vue files and does not interfere with other .js files. Unfortunately the default indent rule when turned on will try to lint both, so in order to make them complementary you can use overrides setting and disable indent rule on .vue files:

json
{
  "rules": {
    "vue/script-indent": ["error", 4, { "baseIndent": 1 }]
  },
  "overrides": [
    {
      "files": ["*.vue"],
      "rules": {
        "indent": "off"
      }
    }
  ]
}

2, "baseIndent": 1

Now loading...

👫相关规则

¥👫 Related Rules

🚀版本

¥🚀 Version

此规则在 eslint-plugin-vue v4.2.0 中引入

¥This rule was introduced in eslint-plugin-vue v4.2.0

🔍代码实现

¥🔍 Implementation

eslint-plugin-vue v10.0 中文网 - 粤ICP备13048890号