Skip to content

vue/html-button-has-type

禁止使用没有明确类型属性的按钮

¥disallow usage of button without an explicit type attribute

如果忘记按钮上的 type 属性,则默认为提交类型。这几乎从来都不是预期的,特别是在你的普通单页应用中。

¥Forgetting the type attribute on a button defaults it to being a submit type. This is nearly never what is intended, especially in your average one-page application.

📖 规则详情

此规则旨在警告按钮类型属性上是否未使用类型或使用无效类型。

¥This rule aims to warn if no type or an invalid type is used on a button type attribute.

Now loading...

🔧选项

¥🔧 Options

json
{
  "vue/html-button-has-type": ["error", {
    "button": true,
    "submit": true,
    "reset": true
  }]
}
  • button ...<button type="button"></button>

    • true(默认)...允许值 button

      ¥true (default) ... allow value button.

    • false ...禁止值 button

      ¥false ... disallow value button.

  • submit ...<button type="submit"></button>

    • true(默认)...允许值 submit

      ¥true (default) ... allow value submit.

    • false ...禁止值 submit

      ¥false ... disallow value submit.

  • reset ...<button type="reset"></button>

    • true(默认)...允许值 reset

      ¥true (default) ... allow value reset.

    • false ...禁止值 reset

      ¥false ... disallow value reset.

🚀版本

¥🚀 Version

此规则在 eslint-plugin-vue v7.6.0 中引入

¥This rule was introduced in eslint-plugin-vue v7.6.0

🔍代码实现

¥🔍 Implementation

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