vue/no-unused-properties
禁止使用未使用的属性
📖 规则详情
此规则旨在消除未使用的属性。
注意
此规则无法检查其他组件对属性的使用(例如 mixins
、通过 $refs
访问属性)以及无法确定作用域的位置的使用。某些对属性的访问可能是隐式的,例如通过变量(例如 this[varName]
)访问数据或计算属性。在这种情况下,默认情况下假定所有属性、方法等都是“已使用”。有关这些情况下“使用”的更严格解释,请参阅 unreferencedOptions
。
🔧 选项
json
{
"vue/no-unused-properties": ["error", {
"groups": ["props"],
"deepData": false,
"ignorePublicMembers": false,
"unreferencedOptions": []
}]
}
groups
(string[]
) 要搜索属性的组数组。默认值为["props"]
。数组的值是以下字符串中的某些值"props"
"data"
"computed"
"methods"
"setup"
deepData
(boolean
) 如果为true
,则将深度搜索在data
中定义的属性的对象。默认值为false
。在groups
中包含"data"
以使用此选项。ignorePublicMembers
(boolean
) 如果为true
,则将忽略用 JSDoc/** @public */
标记 标记的成员。默认值为false
。unreferencedOptions
(string[]
) 用于解释为未引用属性的访问方法数组。目前,有两种这样的方法可用:unknownMemberAsUnreferenced
和returnAsUnreferenced
。请参见下面的示例。
"groups": ["props", "data"]
{ "groups": ["props", "data"], "deepData": true }
"groups": ["props", "computed"]
{ "groups": ["props", "methods"], "ignorePublicMembers": true }
{ "groups": ["computed"], "unreferencedOptions": ["unknownMemberAsUnreferenced"] }
{ "groups": ["computed"], "unreferencedOptions": ["returnAsUnreferenced"] }
🚀 版本
此规则在 eslint-plugin-vue v7.0.0 中引入。