vue/html-button-has-type
要求 button 元素显式指定有效的 type。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
nuxt, opinionated |
不支持 | 规则选项 |
适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。
错误示例
一个按钮省略了 type,另一个使用了不受支持的 foo 类型。
<template>
<button>Click</button>
<button type="foo">Click</button>
</template>
正确示例
按钮指定 button、submit 或 reset;绑定的 type 被视为动态值。
<template>
<button type="button">Click</button>
<button type="submit">Save</button>
<button type="reset">Reset</button>
<button :type="dynamicType">Click</button>
</template>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/html-button-has-type": "warn"
}
},
});
然后运行 vp run lint。