---
url: /docs/guide/usage/linter/rules/vue/max-props.md
---

### 它的作用

强制限制给定的 Vue 组件定义所能拥有的 props 最大数量。

### 为什么这不好？

组件上过多的 props 可能表明它试图做太多事情，因此可能难以维护或理解。

通过限制 props 的数量，开发者会被鼓励避免过于复杂的组件，而是创建更小、更专注的组件，从而更容易推理。

### 示例

对于默认 `{ "maxProps": 1 }` 选项，此规则的**错误**代码示例：

```js
<script setup>
defineProps({
  prop1: String,
  prop2: String,
})
</script>
```

对于默认 `{ "maxProps": 1 }` 选项，此规则的**正确**代码示例：

```js
<script setup>
defineProps({
  prop1: String,
})
</script>
```

## 配置

此规则接受一个包含以下属性的配置对象：

### maxProps

类型：`integer`

默认值：`1`

允许在 Vue SFC 中使用的 props 最大数量。

## 如何使用

## 版本

此规则在 v1.19.0 中添加。

## 参考资料
