vue/no-dupe-keys 正确性
它的作用
禁止字段名重复。
为什么这不好?
Vue 组件选项中的重复键(props、data、computed、methods、setup) 可能会导致意外行为,因为它们在运行时可能会相互覆盖, 并且会在模板中造成名称冲突。
示例
此规则的错误代码示例:
vue
<script>
export default {
props: ["foo"],
computed: {
foo() {},
},
};
</script>此规则的正确代码示例:
vue
<script>
export default {
props: ["foo"],
computed: {
bar() {},
},
};
</script>配置
groups
类型:string[]
默认值:[]
在内置的 props、computed、data、methods 和 setup 组之外, 额外添加要搜索重复键的组名。
如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vue"],
"rules": {
"vue/no-dupe-keys": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vue"],
rules: {
"vue/no-dupe-keys": "error",
},
});bash
oxlint --deny vue/no-dupe-keys --vue-plugin版本
此规则是在 v1.70.0 中添加的。
