vue/max-props 限制
它的作用
强制限制 Vue 组件中的属性数量。
为什么这是个问题?
该规则强制限制 Vue 单文件组件(SFC)中的属性数量,以帮助维护性和降低复杂性。
示例
使用默认配置 { "maxProps": 1 } 时,以下为 错误 的代码示例:
js
<script setup>
defineProps({
prop1: String,
prop2: String,
})
</script>使用默认配置 { "maxProps": 1 } 时,以下为 正确 的代码示例:
js
<script setup>
defineProps({
prop1: String,
})
</script>配置
此规则接受一个包含以下属性的配置对象:
maxProps
type: integer
default: 1
允许在 Vue 单文件组件(SFC)中使用的最大属性数量。
如何使用
可通过配置文件或 CLI 启用此规则:
json
{
"plugins": ["vue"],
"rules": {
"vue/max-props": "error"
}
}bash
oxlint --deny vue/max-props --vue-plugin