vue/no-unused-refs
报告从未在 <script> 中引用的模板 ref(ref="x")。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
nuxt, opinionated |
不支持 | 无 |
适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。
错误示例
模板声明了名为 unused 的 ref,但脚本中没有对应的引用绑定。
<template><input ref="unused" /></template>
<script setup>
const x = 1
</script>
正确示例
模板 ref inputEl 在 script setup 中具有同名的 ref 绑定。
<template><input ref="inputEl" /></template>
<script setup>
import { ref } from 'vue'
const inputEl = ref(null)
</script>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/no-unused-refs": "warn"
}
},
});
然后运行 vp run lint。