vue/no-unused-properties
禁止 defineProps 中定义的未使用属性。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
happy-path, nuxt, ecosystem, opinionated |
不支持 | 无 |
适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。
错误示例
组件将 description 声明为 prop,但只渲染了 title。
<script setup lang="ts">
defineProps<{ title: string; description: string }>();
</script>
<template>
<h1>{{ title }}</h1>
</template>
正确示例
模板引用了两个已声明的 props。
<script setup lang="ts">
defineProps<{ title: string; description: string }>();
</script>
<template>
<h1>{{ title }}</h1>
<p>{{ description }}</p>
</template>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/no-unused-properties": "warn"
}
},
});
然后运行 vp run lint。