Skip to content
← Back to rules

vue/no-reserved-props Correctness

作用

禁止将保留的属性名(例如 keyref)用作 prop 名称。

为什么这不好?

Vue 会对一些属性进行特殊处理(Vue 3 中的 keyref; 此外,Vue 2 中还有 isslotslot-scopeclassstyle)。 使用这些名称之一来声明 prop 会与框架自身的处理发生冲突, 并破坏组件。

示例

以下是此规则的错误代码示例:

vue
<script>
export default {
  props: {
    ref: String,
    key: String,
  },
};
</script>

以下是此规则的正确代码示例:

vue
<script>
export default {
  props: {
    foo: String,
  },
};
</script>

配置

vueVersion

type: integer

default: 3

用于保留属性集合的 Vue 主版本。Vue 2 保留 更多名称(isslotclassstyle 等)而不是 Vue 3。

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["vue"],
  "rules": {
    "vue/no-reserved-props": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["vue"],
  rules: {
    "vue/no-reserved-props": "error",
  },
});
bash
oxlint --deny vue/no-reserved-props --vue-plugin

版本

此规则在 v1.69.0 中添加。

参考资料