Skip to content

vue/no-unused-properties

禁止未使用的属性

¥disallow unused properties

📖 规则详情

此规则旨在消除未使用的属性。

¥This rule is aimed at eliminating unused properties.

注意

此规则无法检查其他组件对属性的使用(例如 mixins,通过 $refs 访问属性)以及在无法确定范围的地方使用。某些属性访问可能是隐含的,例如访问数据或通过变量(如 this[varName])计算。在这种情况下,默认假设所有属性、方法等都是 'used'。请参阅 unreferencedOptions 以了解这些情况下对 'use' 的更严格解释。

¥This rule cannot check for use of properties by other components (e.g. mixins, property access via $refs) and use in places where the scope cannot be determined. Some access to properties might be implied, for example accessing data or computed via a variable such as this[varName]. In this case, the default is to assume all properties, methods, etc. are 'used'. See the unreferencedOptions for a more strict interpretation of 'use' in these cases.

Now loading...
Now loading...

🔧选项

¥🔧 Options

json
{
  "vue/no-unused-properties": ["error", {
    "groups": ["props"],
    "deepData": false,
    "ignorePublicMembers": false,
    "unreferencedOptions": []
  }]
}
  • groupsstring[])用于搜索属性的组数组。默认值为 ["props"]。数组的值是以下一些字符串:

    ¥groups (string[]) Array of groups to search for properties. Default is ["props"]. The value of the array is some of the following strings:

    • "props"

    • "data"

    • "computed"

    • "methods"

    • "setup"

  • deepDataboolean)如果为 true,则将深入搜索在 data 中定义的属性的对象。默认值为 false。在 groups 中包含 "data" 以使用此选项。

    ¥deepData (boolean) If true, the object of the property defined in data will be searched deeply. Default is false. Include "data" in groups to use this option.

  • ignorePublicMembersboolean)如果为 true,则将忽略标有 JSDoc /** @public */ 标签 的成员。默认值为 false

    ¥ignorePublicMembers (boolean) If true, members marked with a JSDoc /** @public */ tag will be ignored. Default is false.

  • unreferencedOptionsstring[])应解释为保留未引用属性的访问方法数组。目前,有两种方法可用:unknownMemberAsUnreferencedreturnAsUnreferenced。请参阅下面的示例。

    ¥unreferencedOptions (string[]) Array of access methods that should be interpreted as leaving properties unreferenced. Currently, two such methods are available: unknownMemberAsUnreferenced, and returnAsUnreferenced. See examples below.

"groups": ["props", "data"]

Now loading...
Now loading...

{ "groups": ["props", "data"], "deepData": true }

Now loading...

"groups": ["props", "computed"]

Now loading...
Now loading...

{ "groups": ["props", "methods"], "ignorePublicMembers": true }

Now loading...

{ "groups": ["computed"], "unreferencedOptions": ["unknownMemberAsUnreferenced"] }

Now loading...

{ "groups": ["computed"], "unreferencedOptions": ["returnAsUnreferenced"] }

Now loading...

🚀版本

¥🚀 Version

此规则在 eslint-plugin-vue v7.0.0 中引入

¥This rule was introduced in eslint-plugin-vue v7.0.0

🔍代码实现

¥🔍 Implementation

eslint-plugin-vue v10.0 中文网 - 粤ICP备13048890号