vue/no-reserved-props Correctness
作用
禁止将保留的属性名(例如 key、ref)用作 prop 名称。
为什么这不好?
Vue 会对一些属性进行特殊处理(Vue 3 中的 key 和 ref; 此外,Vue 2 中还有 is、slot、slot-scope、class 和 style)。 使用这些名称之一来声明 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 保留 更多名称(is、slot、class、style 等)而不是 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 中添加。
