@fast-china/eslint-config 2.1.7 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/CONTRIBUTING.md +2 -2
- package/README.md +66 -142
- package/README.zh.md +64 -142
- package/dist/configs/environment.mjs +2 -0
- package/dist/configs/environment.mjs.map +1 -1
- package/dist/configs/ignores.mjs +0 -1
- package/dist/configs/ignores.mjs.map +1 -1
- package/dist/configs/import.mjs +4 -1
- package/dist/configs/import.mjs.map +1 -1
- package/dist/configs/index.d.mts +2 -2
- package/dist/configs/index.mjs +2 -2
- package/dist/configs/javascript.mjs +3 -1
- package/dist/configs/javascript.mjs.map +1 -1
- package/dist/configs/json.mjs +3 -1
- package/dist/configs/json.mjs.map +1 -1
- package/dist/configs/markdown.d.mts +2 -1
- package/dist/configs/markdown.mjs +4 -2
- package/dist/configs/markdown.mjs.map +1 -1
- package/dist/configs/prettier.mjs +1 -1
- package/dist/configs/prettier.mjs.map +1 -1
- package/dist/configs/sort-package.d.mts +1 -1
- package/dist/configs/sort-package.mjs +1 -1
- package/dist/configs/sort-package.mjs.map +1 -1
- package/dist/configs/sort-tsconfig.d.mts +2 -2
- package/dist/configs/sort-tsconfig.mjs +2 -2
- package/dist/configs/sort-tsconfig.mjs.map +1 -1
- package/dist/configs/typescript.d.mts +11 -7
- package/dist/configs/typescript.mjs +25 -22
- package/dist/configs/typescript.mjs.map +1 -1
- package/dist/configs/uniapp.mjs +19 -13
- package/dist/configs/uniapp.mjs.map +1 -1
- package/dist/configs/vue.d.mts +18 -3
- package/dist/configs/vue.mjs +59 -9
- package/dist/configs/vue.mjs.map +1 -1
- package/dist/constants/index.d.mts +4 -0
- package/dist/constants/index.mjs +5 -1
- package/dist/constants/index.mjs.map +1 -1
- package/dist/index.d.mts +37 -58
- package/dist/index.mjs +43 -47
- package/dist/index.mjs.map +1 -1
- package/dist/rules/angular.d.mts +28 -0
- package/dist/rules/angular.mjs +28 -0
- package/dist/rules/angular.mjs.map +1 -1
- package/dist/rules/common.d.mts +16 -6
- package/dist/rules/common.mjs +16 -13
- package/dist/rules/common.mjs.map +1 -1
- package/dist/rules/import.d.mts +9 -0
- package/dist/rules/import.mjs +24 -0
- package/dist/rules/import.mjs.map +1 -1
- package/dist/rules/index.d.mts +2 -2
- package/dist/rules/index.mjs +2 -2
- package/dist/rules/javascript.d.mts +18 -0
- package/dist/rules/javascript.mjs +18 -0
- package/dist/rules/javascript.mjs.map +1 -1
- package/dist/rules/lodash.d.mts +2 -0
- package/dist/rules/lodash.mjs +6 -2
- package/dist/rules/lodash.mjs.map +1 -1
- package/dist/rules/react.d.mts +13 -0
- package/dist/rules/react.mjs +13 -0
- package/dist/rules/react.mjs.map +1 -1
- package/dist/rules/regexp.d.mts +25 -0
- package/dist/rules/regexp.mjs +25 -0
- package/dist/rules/regexp.mjs.map +1 -1
- package/dist/rules/sort-package.d.mts +3 -1
- package/dist/rules/sort-package.mjs +3 -1
- package/dist/rules/sort-package.mjs.map +1 -1
- package/dist/rules/sort-tsconfig.d.mts +3 -1
- package/dist/rules/sort-tsconfig.mjs +3 -1
- package/dist/rules/sort-tsconfig.mjs.map +1 -1
- package/dist/rules/typescript.d.mts +81 -13
- package/dist/rules/typescript.mjs +83 -15
- package/dist/rules/typescript.mjs.map +1 -1
- package/dist/rules/vue.d.mts +65 -10
- package/dist/rules/vue.mjs +41 -14
- package/dist/rules/vue.mjs.map +1 -1
- package/docs/engineering-audit.zh.md +45 -49
- package/docs/rules/angular.zh.md +721 -0
- package/docs/rules/core.zh.md +3031 -0
- package/docs/rules/index.zh.md +38 -0
- package/docs/rules/json.zh.md +784 -0
- package/docs/rules/markdown.zh.md +449 -0
- package/docs/rules/react.zh.md +2091 -0
- package/docs/rules/typescript.zh.md +2051 -0
- package/docs/rules/vue.zh.md +3016 -0
- package/docs/rules-risk.md +85 -91
- package/docs/rules-risk.zh.md +76 -82
- package/package.json +4 -2
|
@@ -0,0 +1,3016 @@
|
|
|
1
|
+
<!-- 此文件由 scripts/rules-docs.ts 生成,请勿手工编辑。 -->
|
|
2
|
+
|
|
3
|
+
# Vue 3、JSX/TSX 与 UniApp
|
|
4
|
+
|
|
5
|
+
本页记录当前依赖版本和仓库配置最终产生的 109 条规则。每条规则均列出实际严重级别、生效范围、上游说明、常见报告以及错误/正确示例。
|
|
6
|
+
|
|
7
|
+
## 仓库显式规则(15 条)
|
|
8
|
+
|
|
9
|
+
### `vue/attribute-hyphenation`
|
|
10
|
+
|
|
11
|
+
自定义组件的模板属性统一使用 kebab-case;脚本中的 Props 与 JSX 属性仍使用 camelCase。
|
|
12
|
+
|
|
13
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
14
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
15
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/attribute-hyphenation.html)
|
|
16
|
+
- 常见报告:`Attribute '{{text}}' must be hyphenated.`;`Attribute '{{text}}' can't be hyphenated.`
|
|
17
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
18
|
+
|
|
19
|
+
错误示例:
|
|
20
|
+
|
|
21
|
+
<!-- prettier-ignore -->
|
|
22
|
+
````vue
|
|
23
|
+
<template>
|
|
24
|
+
<UserCard userName="Fast" />
|
|
25
|
+
</template>
|
|
26
|
+
````
|
|
27
|
+
|
|
28
|
+
正确示例:
|
|
29
|
+
|
|
30
|
+
<!-- prettier-ignore -->
|
|
31
|
+
````vue
|
|
32
|
+
<template>
|
|
33
|
+
<UserCard user-name="Fast" />
|
|
34
|
+
</template>
|
|
35
|
+
````
|
|
36
|
+
|
|
37
|
+
### `vue/attributes-order`
|
|
38
|
+
|
|
39
|
+
模板属性按定义、循环、条件、修饰、唯一属性、全局属性、普通属性、事件和内容排序。
|
|
40
|
+
|
|
41
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
42
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
43
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/attributes-order.html)
|
|
44
|
+
- 常见报告:`Attribute "{{currentNode}}" should go before "{{prevNode}}".`
|
|
45
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
46
|
+
|
|
47
|
+
错误示例:
|
|
48
|
+
|
|
49
|
+
<!-- prettier-ignore -->
|
|
50
|
+
````vue
|
|
51
|
+
<template>
|
|
52
|
+
<button @click="save" v-if="ready" id="save">Save</button>
|
|
53
|
+
</template>
|
|
54
|
+
````
|
|
55
|
+
|
|
56
|
+
正确示例:
|
|
57
|
+
|
|
58
|
+
<!-- prettier-ignore -->
|
|
59
|
+
````vue
|
|
60
|
+
<template>
|
|
61
|
+
<button v-if="ready" id="save" @click="save">Save</button>
|
|
62
|
+
</template>
|
|
63
|
+
````
|
|
64
|
+
|
|
65
|
+
### `vue/custom-event-name-casing`
|
|
66
|
+
|
|
67
|
+
`emit`、`emits` 和事件处理引用中的自定义事件名称统一使用 camelCase,原生 DOM 事件不受影响。
|
|
68
|
+
|
|
69
|
+
- 生效级别与范围:error: Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
70
|
+
- 自动修复:不支持或上游未声明
|
|
71
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/custom-event-name-casing.html)
|
|
72
|
+
- 常见报告:`Custom event name '{{name}}' must be {{caseType}}.`
|
|
73
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
74
|
+
|
|
75
|
+
错误示例:
|
|
76
|
+
|
|
77
|
+
<!-- prettier-ignore -->
|
|
78
|
+
````vue
|
|
79
|
+
<script setup>const emit = defineEmits(["saveItem"]);
|
|
80
|
+
emit("save-item");</script>
|
|
81
|
+
````
|
|
82
|
+
|
|
83
|
+
正确示例:
|
|
84
|
+
|
|
85
|
+
<!-- prettier-ignore -->
|
|
86
|
+
````vue
|
|
87
|
+
<script setup>const emit = defineEmits(["saveItem"]);
|
|
88
|
+
emit("saveItem");</script>
|
|
89
|
+
````
|
|
90
|
+
|
|
91
|
+
### `vue/multi-word-component-names`
|
|
92
|
+
|
|
93
|
+
允许 `App`、`Layout` 等约定俗成的单词组件名。
|
|
94
|
+
|
|
95
|
+
- 生效级别与范围:默认关闭(本地显式覆写)
|
|
96
|
+
- 关闭范围:Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
97
|
+
- 自动修复:不支持或上游未声明
|
|
98
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/multi-word-component-names.html)
|
|
99
|
+
- 常见报告:`Component name "{{value}}" should always be multi-word.`
|
|
100
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
101
|
+
|
|
102
|
+
错误示例:
|
|
103
|
+
|
|
104
|
+
<!-- prettier-ignore -->
|
|
105
|
+
````vue
|
|
106
|
+
<script>
|
|
107
|
+
export default { name: 'Card' };
|
|
108
|
+
</script>
|
|
109
|
+
````
|
|
110
|
+
|
|
111
|
+
正确示例:
|
|
112
|
+
|
|
113
|
+
<!-- prettier-ignore -->
|
|
114
|
+
````vue
|
|
115
|
+
<script>
|
|
116
|
+
export default { name: 'UserCard' };
|
|
117
|
+
</script>
|
|
118
|
+
````
|
|
119
|
+
|
|
120
|
+
### `vue/no-dupe-keys`
|
|
121
|
+
|
|
122
|
+
`props`、`data`、`computed`、`methods` 等选项中禁止同名键,避免成员互相遮蔽。
|
|
123
|
+
|
|
124
|
+
- 生效级别与范围:error: Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
125
|
+
- 自动修复:不支持或上游未声明
|
|
126
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-dupe-keys.html)
|
|
127
|
+
- 常见报告:`Duplicate key '{{name}}'. May cause name collision in script or template tag.`
|
|
128
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
129
|
+
|
|
130
|
+
错误示例:
|
|
131
|
+
|
|
132
|
+
<!-- prettier-ignore -->
|
|
133
|
+
````vue
|
|
134
|
+
<script>export default { props: ["name"], data: () => ({ name: "" }) };</script>
|
|
135
|
+
````
|
|
136
|
+
|
|
137
|
+
正确示例:
|
|
138
|
+
|
|
139
|
+
<!-- prettier-ignore -->
|
|
140
|
+
````vue
|
|
141
|
+
<script>export default { props: ["name"], data: () => ({ draftName: "" }) };</script>
|
|
142
|
+
````
|
|
143
|
+
|
|
144
|
+
### `vue/no-mutating-props`
|
|
145
|
+
|
|
146
|
+
Props 属于父组件只读输入,子组件应通过 emit 或本地状态更新。
|
|
147
|
+
|
|
148
|
+
- 生效级别与范围:error: Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
149
|
+
- 自动修复:不支持或上游未声明
|
|
150
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-mutating-props.html)
|
|
151
|
+
- 常见报告:`Unexpected mutation of "{{key}}" prop.`
|
|
152
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
153
|
+
|
|
154
|
+
错误示例:
|
|
155
|
+
|
|
156
|
+
<!-- prettier-ignore -->
|
|
157
|
+
````vue
|
|
158
|
+
<script setup lang="ts">const props = defineProps<{ count: number }>();
|
|
159
|
+
props.count++;</script>
|
|
160
|
+
````
|
|
161
|
+
|
|
162
|
+
正确示例:
|
|
163
|
+
|
|
164
|
+
<!-- prettier-ignore -->
|
|
165
|
+
````vue
|
|
166
|
+
<script setup lang="ts">const props = defineProps<{ count: number }>();
|
|
167
|
+
const emit = defineEmits<{ "update:count": [value: number] }>();
|
|
168
|
+
emit("update:count", props.count + 1);</script>
|
|
169
|
+
````
|
|
170
|
+
|
|
171
|
+
### `vue/no-ref-object-reactivity-loss`
|
|
172
|
+
|
|
173
|
+
禁止以会丢失响应性的方式解构或传递 ref 对象,确保后续更新仍能被 Vue 追踪。
|
|
174
|
+
|
|
175
|
+
- 生效级别与范围:error: Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
176
|
+
- 自动修复:不支持或上游未声明
|
|
177
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-ref-object-reactivity-loss.html)
|
|
178
|
+
- 常见报告:`Getting a value from the ref object in the same scope will cause the value to lose reactivity.`;`Getting a reactive variable in the same scope will cause the value to lose reactivity.`
|
|
179
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
180
|
+
|
|
181
|
+
错误示例:
|
|
182
|
+
|
|
183
|
+
<!-- prettier-ignore -->
|
|
184
|
+
````vue
|
|
185
|
+
<script setup>import { ref } from 'vue';
|
|
186
|
+
const count = ref(0).value;</script>
|
|
187
|
+
````
|
|
188
|
+
|
|
189
|
+
正确示例:
|
|
190
|
+
|
|
191
|
+
<!-- prettier-ignore -->
|
|
192
|
+
````vue
|
|
193
|
+
<script setup>import { ref } from 'vue';
|
|
194
|
+
const count = ref(0);</script>
|
|
195
|
+
<template><p>{{ count }}</p></template>
|
|
196
|
+
````
|
|
197
|
+
|
|
198
|
+
### `vue/no-reserved-component-names`
|
|
199
|
+
|
|
200
|
+
组件名不能占用 Vue 内置组件或平台保留名称。
|
|
201
|
+
|
|
202
|
+
- 生效级别与范围:error: Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
203
|
+
- 自动修复:不支持或上游未声明
|
|
204
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-reserved-component-names.html)
|
|
205
|
+
- 常见报告:`Name "{{name}}" is reserved.`;`Name "{{name}}" is reserved in HTML.`;`Name "{{name}}" is reserved in Vue.js.`
|
|
206
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
207
|
+
|
|
208
|
+
错误示例:
|
|
209
|
+
|
|
210
|
+
<!-- prettier-ignore -->
|
|
211
|
+
````vue
|
|
212
|
+
<script setup>defineOptions({ name: "div" });</script>
|
|
213
|
+
````
|
|
214
|
+
|
|
215
|
+
正确示例:
|
|
216
|
+
|
|
217
|
+
<!-- prettier-ignore -->
|
|
218
|
+
````vue
|
|
219
|
+
<script setup>defineOptions({ name: "PageContainer" });</script>
|
|
220
|
+
````
|
|
221
|
+
|
|
222
|
+
### `vue/no-setup-props-reactivity-loss`
|
|
223
|
+
|
|
224
|
+
`setup` 中直接解构 props 会丢失响应性,要求保留 props 引用或使用 `toRefs` 等响应式转换。
|
|
225
|
+
|
|
226
|
+
- 生效级别与范围:error: Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
227
|
+
- 自动修复:不支持或上游未声明
|
|
228
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-setup-props-reactivity-loss.html)
|
|
229
|
+
- 常见报告:`Destructuring the 'props' will cause the value to lose reactivity.`;`Getting a value from the 'props' in root scope of '{{scopeName}}' will cause the value to lose reactivity.`
|
|
230
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
231
|
+
|
|
232
|
+
错误示例:
|
|
233
|
+
|
|
234
|
+
<!-- prettier-ignore -->
|
|
235
|
+
````vue
|
|
236
|
+
<script>
|
|
237
|
+
export default { setup({ count }) { return { count }; } };
|
|
238
|
+
</script>
|
|
239
|
+
````
|
|
240
|
+
|
|
241
|
+
正确示例:
|
|
242
|
+
|
|
243
|
+
<!-- prettier-ignore -->
|
|
244
|
+
````vue
|
|
245
|
+
<script>
|
|
246
|
+
export default { setup(props) { return { count: toRef(props, 'count') }; } };
|
|
247
|
+
</script>
|
|
248
|
+
````
|
|
249
|
+
|
|
250
|
+
### `vue/no-v-html`
|
|
251
|
+
|
|
252
|
+
`v-html` 可能引入 XSS;保留警告以兼容经过净化的富文本场景。
|
|
253
|
+
|
|
254
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
255
|
+
- 自动修复:不支持或上游未声明
|
|
256
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-v-html.html)
|
|
257
|
+
- 常见报告:`'v-html' directive can lead to XSS attack.`
|
|
258
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
259
|
+
|
|
260
|
+
错误示例:
|
|
261
|
+
|
|
262
|
+
<!-- prettier-ignore -->
|
|
263
|
+
````vue
|
|
264
|
+
<template>
|
|
265
|
+
<div v-html="untrustedHtml" />
|
|
266
|
+
</template>
|
|
267
|
+
````
|
|
268
|
+
|
|
269
|
+
正确示例:
|
|
270
|
+
|
|
271
|
+
<!-- prettier-ignore -->
|
|
272
|
+
````vue
|
|
273
|
+
<template>
|
|
274
|
+
<div>{{ plainText }}</div>
|
|
275
|
+
</template>
|
|
276
|
+
````
|
|
277
|
+
|
|
278
|
+
### `vue/no-v-text-v-html-on-component`
|
|
279
|
+
|
|
280
|
+
禁止在组件节点使用 `v-text` 或 `v-html`,避免覆盖组件内容并模糊数据边界。
|
|
281
|
+
|
|
282
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
283
|
+
- 自动修复:不支持或上游未声明
|
|
284
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-v-text-v-html-on-component.html)
|
|
285
|
+
- 常见报告:`Using {{directiveName}} on component may break component's content.`
|
|
286
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
287
|
+
|
|
288
|
+
错误示例:
|
|
289
|
+
|
|
290
|
+
<!-- prettier-ignore -->
|
|
291
|
+
````vue
|
|
292
|
+
<template>
|
|
293
|
+
<UserCard v-html="content" />
|
|
294
|
+
</template>
|
|
295
|
+
````
|
|
296
|
+
|
|
297
|
+
正确示例:
|
|
298
|
+
|
|
299
|
+
<!-- prettier-ignore -->
|
|
300
|
+
````vue
|
|
301
|
+
<template>
|
|
302
|
+
<UserCard>{{ content }}</UserCard>
|
|
303
|
+
</template>
|
|
304
|
+
````
|
|
305
|
+
|
|
306
|
+
### `vue/one-component-per-file`
|
|
307
|
+
|
|
308
|
+
允许在一个 SFC 中声明仅供当前文件使用的小型辅助组件。
|
|
309
|
+
|
|
310
|
+
- 生效级别与范围:默认关闭(本地显式覆写)
|
|
311
|
+
- 关闭范围:Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
312
|
+
- 自动修复:不支持或上游未声明
|
|
313
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/one-component-per-file.html)
|
|
314
|
+
- 常见报告:`There is more than one component in this file.`
|
|
315
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
316
|
+
|
|
317
|
+
错误示例:
|
|
318
|
+
|
|
319
|
+
<!-- prettier-ignore -->
|
|
320
|
+
````vue
|
|
321
|
+
<script>
|
|
322
|
+
export const Header = defineComponent({});
|
|
323
|
+
export const Footer = defineComponent({});
|
|
324
|
+
</script>
|
|
325
|
+
````
|
|
326
|
+
|
|
327
|
+
正确示例:
|
|
328
|
+
|
|
329
|
+
<!-- prettier-ignore -->
|
|
330
|
+
````vue
|
|
331
|
+
<script>
|
|
332
|
+
export default defineComponent({ name: 'PageHeader' });
|
|
333
|
+
</script>
|
|
334
|
+
````
|
|
335
|
+
|
|
336
|
+
### `vue/prefer-import-from-vue`
|
|
337
|
+
|
|
338
|
+
允许直接使用 Vue 子包入口,兼容编译器与运行时等明确子模块导入。
|
|
339
|
+
|
|
340
|
+
- 生效级别与范围:默认关闭(本地显式覆写)
|
|
341
|
+
- 关闭范围:Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
342
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
343
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/prefer-import-from-vue.html)
|
|
344
|
+
- 常见报告:`Import from 'vue' instead of '{{source}}'.`
|
|
345
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
346
|
+
|
|
347
|
+
错误示例:
|
|
348
|
+
|
|
349
|
+
<!-- prettier-ignore -->
|
|
350
|
+
````vue
|
|
351
|
+
<script>
|
|
352
|
+
import { ref } from '@vue/reactivity';
|
|
353
|
+
</script>
|
|
354
|
+
````
|
|
355
|
+
|
|
356
|
+
正确示例:
|
|
357
|
+
|
|
358
|
+
<!-- prettier-ignore -->
|
|
359
|
+
````vue
|
|
360
|
+
<script>
|
|
361
|
+
import { ref } from 'vue';
|
|
362
|
+
</script>
|
|
363
|
+
````
|
|
364
|
+
|
|
365
|
+
### `vue/require-default-prop`
|
|
366
|
+
|
|
367
|
+
TypeScript 类型 props 和 `required` 声明已能表达可选性,不强制每个可选 prop 提供默认值。
|
|
368
|
+
|
|
369
|
+
- 生效级别与范围:默认关闭(本地显式覆写)
|
|
370
|
+
- 关闭范围:Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
371
|
+
- 自动修复:不支持或上游未声明
|
|
372
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/require-default-prop.html)
|
|
373
|
+
- 常见报告:`Prop '{{propName}}' requires default value to be set.`
|
|
374
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
375
|
+
|
|
376
|
+
错误示例:
|
|
377
|
+
|
|
378
|
+
<!-- prettier-ignore -->
|
|
379
|
+
````vue
|
|
380
|
+
<script>
|
|
381
|
+
export default { props: { name: String } };
|
|
382
|
+
</script>
|
|
383
|
+
````
|
|
384
|
+
|
|
385
|
+
正确示例:
|
|
386
|
+
|
|
387
|
+
<!-- prettier-ignore -->
|
|
388
|
+
````vue
|
|
389
|
+
<script>
|
|
390
|
+
export default { props: { name: { type: String, default: '' } } };
|
|
391
|
+
</script>
|
|
392
|
+
````
|
|
393
|
+
|
|
394
|
+
### `vue/require-explicit-emits`
|
|
395
|
+
|
|
396
|
+
组件事件必须显式声明,形成可检查的对外事件契约。
|
|
397
|
+
|
|
398
|
+
- 生效级别与范围:error: Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX
|
|
399
|
+
- 自动修复:不支持或上游未声明
|
|
400
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/require-explicit-emits.html)
|
|
401
|
+
- 常见报告:`The "{{name}}" event has been triggered but not declared on {{emitsKind}}.`;`Add the "{{name}}" to {{emitsKind}}.`;`Add the {{emitsKind}} with array syntax and define "{{name}}" event.`
|
|
402
|
+
- 示例类型:仓库显式规则的直接代码示例
|
|
403
|
+
|
|
404
|
+
错误示例:
|
|
405
|
+
|
|
406
|
+
<!-- prettier-ignore -->
|
|
407
|
+
````vue
|
|
408
|
+
<script setup lang="ts">const emit = defineEmits<{ cancel: [] }>();
|
|
409
|
+
emit("save");</script>
|
|
410
|
+
````
|
|
411
|
+
|
|
412
|
+
正确示例:
|
|
413
|
+
|
|
414
|
+
<!-- prettier-ignore -->
|
|
415
|
+
````vue
|
|
416
|
+
<script setup lang="ts">const emit = defineEmits<{ save: [] }>();
|
|
417
|
+
emit("save");</script>
|
|
418
|
+
````
|
|
419
|
+
|
|
420
|
+
## 第三方预置规则(94 条)
|
|
421
|
+
|
|
422
|
+
### `vue/block-order`
|
|
423
|
+
|
|
424
|
+
检查该规则对应的代码约束。上游说明:enforce order of component top-level elements
|
|
425
|
+
|
|
426
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
427
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
428
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/block-order.html)
|
|
429
|
+
- 常见报告:`'<{{elementName}}{{elementAttributes}}>' should be above '<{{firstUnorderedName}}{{firstUnorderedAttributes}}>' on line {{line}}.`
|
|
430
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
431
|
+
|
|
432
|
+
错误示例:
|
|
433
|
+
|
|
434
|
+
<!-- prettier-ignore -->
|
|
435
|
+
````vue
|
|
436
|
+
<style scoped>.page { color: red; }</style>
|
|
437
|
+
<script setup>const title = 'Page';</script>
|
|
438
|
+
<template><h1>{{ title }}</h1></template>
|
|
439
|
+
````
|
|
440
|
+
|
|
441
|
+
正确示例:
|
|
442
|
+
|
|
443
|
+
<!-- prettier-ignore -->
|
|
444
|
+
````vue
|
|
445
|
+
<script setup>const title = 'Page';</script>
|
|
446
|
+
<template><h1>{{ title }}</h1></template>
|
|
447
|
+
<style scoped>.page { color: red; }</style>
|
|
448
|
+
````
|
|
449
|
+
|
|
450
|
+
### `vue/comment-directive`
|
|
451
|
+
|
|
452
|
+
检查该规则对应的代码约束。上游说明:support comment-directives in `<template>`
|
|
453
|
+
|
|
454
|
+
- 生效级别与范围:error: Vue SFC
|
|
455
|
+
- 自动修复:不支持或上游未声明
|
|
456
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/comment-directive.html)
|
|
457
|
+
- 常见报告:`--block {{key}}`;`++block`;`--line {{key}}`
|
|
458
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
459
|
+
|
|
460
|
+
错误示例:
|
|
461
|
+
|
|
462
|
+
<!-- prettier-ignore -->
|
|
463
|
+
````vue
|
|
464
|
+
<template>
|
|
465
|
+
// eslint-disable-next-line vue/no-v-html
|
|
466
|
+
<div v-html="html" />
|
|
467
|
+
</template>
|
|
468
|
+
````
|
|
469
|
+
|
|
470
|
+
正确示例:
|
|
471
|
+
|
|
472
|
+
<!-- prettier-ignore -->
|
|
473
|
+
````vue
|
|
474
|
+
<template>
|
|
475
|
+
<!-- eslint-disable-next-line vue/no-v-html -->
|
|
476
|
+
<div v-html="html" />
|
|
477
|
+
</template>
|
|
478
|
+
````
|
|
479
|
+
|
|
480
|
+
### `vue/component-definition-name-casing`
|
|
481
|
+
|
|
482
|
+
检查该规则对应的代码约束。上游说明:enforce specific casing for component definition name
|
|
483
|
+
|
|
484
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
485
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
486
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/component-definition-name-casing.html)
|
|
487
|
+
- 常见报告:`Property name "{{value}}" is not {{caseType}}.`
|
|
488
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
489
|
+
|
|
490
|
+
错误示例:
|
|
491
|
+
|
|
492
|
+
<!-- prettier-ignore -->
|
|
493
|
+
````vue
|
|
494
|
+
<script>
|
|
495
|
+
export default { name: 'user-card' };
|
|
496
|
+
</script>
|
|
497
|
+
````
|
|
498
|
+
|
|
499
|
+
正确示例:
|
|
500
|
+
|
|
501
|
+
<!-- prettier-ignore -->
|
|
502
|
+
````vue
|
|
503
|
+
<script>
|
|
504
|
+
export default { name: 'UserCard' };
|
|
505
|
+
</script>
|
|
506
|
+
````
|
|
507
|
+
|
|
508
|
+
### `vue/first-attribute-linebreak`
|
|
509
|
+
|
|
510
|
+
检查该规则对应的代码约束。上游说明:enforce the location of first attribute
|
|
511
|
+
|
|
512
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
513
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
514
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/first-attribute-linebreak.html)
|
|
515
|
+
- 常见报告:`Expected a linebreak before this attribute.`;`Expected no linebreak before this attribute.`
|
|
516
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
517
|
+
|
|
518
|
+
错误示例:
|
|
519
|
+
|
|
520
|
+
<!-- prettier-ignore -->
|
|
521
|
+
````vue
|
|
522
|
+
<template>
|
|
523
|
+
<UserCard name="Fast"
|
|
524
|
+
:active="true" />
|
|
525
|
+
</template>
|
|
526
|
+
````
|
|
527
|
+
|
|
528
|
+
正确示例:
|
|
529
|
+
|
|
530
|
+
<!-- prettier-ignore -->
|
|
531
|
+
````vue
|
|
532
|
+
<template>
|
|
533
|
+
<UserCard
|
|
534
|
+
name="Fast"
|
|
535
|
+
:active="true"
|
|
536
|
+
/>
|
|
537
|
+
</template>
|
|
538
|
+
````
|
|
539
|
+
|
|
540
|
+
### `vue/jsx-uses-vars`
|
|
541
|
+
|
|
542
|
+
检查该规则对应的代码约束。上游说明:prevent variables used in JSX to be marked as unused
|
|
543
|
+
|
|
544
|
+
- 生效级别与范围:error: Vue SFC
|
|
545
|
+
- 自动修复:不支持或上游未声明
|
|
546
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/jsx-uses-vars.html)
|
|
547
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
548
|
+
|
|
549
|
+
错误示例:
|
|
550
|
+
|
|
551
|
+
<!-- prettier-ignore -->
|
|
552
|
+
````tsx
|
|
553
|
+
const UserCard = defineComponent({});
|
|
554
|
+
const view = <div />;
|
|
555
|
+
````
|
|
556
|
+
|
|
557
|
+
正确示例:
|
|
558
|
+
|
|
559
|
+
<!-- prettier-ignore -->
|
|
560
|
+
````tsx
|
|
561
|
+
const UserCard = defineComponent({});
|
|
562
|
+
const view = <UserCard />;
|
|
563
|
+
````
|
|
564
|
+
|
|
565
|
+
### `vue/no-arrow-functions-in-watch`
|
|
566
|
+
|
|
567
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using arrow functions to define watcher
|
|
568
|
+
|
|
569
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
570
|
+
- 自动修复:不支持或上游未声明
|
|
571
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-arrow-functions-in-watch.html)
|
|
572
|
+
- 常见报告:`You should not use an arrow function to define a watcher.`
|
|
573
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
574
|
+
|
|
575
|
+
错误示例:
|
|
576
|
+
|
|
577
|
+
<!-- prettier-ignore -->
|
|
578
|
+
````vue
|
|
579
|
+
<script>
|
|
580
|
+
export default { watch: { count: () => { this.save(); } } };
|
|
581
|
+
</script>
|
|
582
|
+
````
|
|
583
|
+
|
|
584
|
+
正确示例:
|
|
585
|
+
|
|
586
|
+
<!-- prettier-ignore -->
|
|
587
|
+
````vue
|
|
588
|
+
<script>
|
|
589
|
+
export default { watch: { count() { this.save(); } } };
|
|
590
|
+
</script>
|
|
591
|
+
````
|
|
592
|
+
|
|
593
|
+
### `vue/no-async-in-computed-properties`
|
|
594
|
+
|
|
595
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow asynchronous actions in computed properties
|
|
596
|
+
|
|
597
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
598
|
+
- 自动修复:不支持或上游未声明
|
|
599
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-async-in-computed-properties.html)
|
|
600
|
+
- 常见报告:`Unexpected {{expressionName}} in computed function.`;`Unexpected {{expressionName}} in "{{propertyName}}" computed property.`
|
|
601
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
602
|
+
|
|
603
|
+
错误示例:
|
|
604
|
+
|
|
605
|
+
<!-- prettier-ignore -->
|
|
606
|
+
````vue
|
|
607
|
+
<script>
|
|
608
|
+
export default { computed: { async user() { return await loadUser(); } } };
|
|
609
|
+
</script>
|
|
610
|
+
````
|
|
611
|
+
|
|
612
|
+
正确示例:
|
|
613
|
+
|
|
614
|
+
<!-- prettier-ignore -->
|
|
615
|
+
````vue
|
|
616
|
+
<script>
|
|
617
|
+
export default { data: () => ({ user: null }), async mounted() { this.user = await loadUser(); } };
|
|
618
|
+
</script>
|
|
619
|
+
````
|
|
620
|
+
|
|
621
|
+
### `vue/no-child-content`
|
|
622
|
+
|
|
623
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow element's child contents which would be overwritten by a directive like `v-html` or `v-text`
|
|
624
|
+
|
|
625
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
626
|
+
- 自动修复:不支持或上游未声明
|
|
627
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-child-content.html)
|
|
628
|
+
- 常见报告:`Child content is disallowed because it will be overwritten by the v-{{ directiveName }} directive.`;`Remove child content.`
|
|
629
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
630
|
+
|
|
631
|
+
错误示例:
|
|
632
|
+
|
|
633
|
+
<!-- prettier-ignore -->
|
|
634
|
+
````vue
|
|
635
|
+
<template>
|
|
636
|
+
<div v-html="html">Fallback</div>
|
|
637
|
+
</template>
|
|
638
|
+
````
|
|
639
|
+
|
|
640
|
+
正确示例:
|
|
641
|
+
|
|
642
|
+
<!-- prettier-ignore -->
|
|
643
|
+
````vue
|
|
644
|
+
<template>
|
|
645
|
+
<div v-html="html" />
|
|
646
|
+
</template>
|
|
647
|
+
````
|
|
648
|
+
|
|
649
|
+
### `vue/no-computed-properties-in-data`
|
|
650
|
+
|
|
651
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow accessing computed properties in `data`
|
|
652
|
+
|
|
653
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
654
|
+
- 自动修复:不支持或上游未声明
|
|
655
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-computed-properties-in-data.html)
|
|
656
|
+
- 常见报告:`The computed property cannot be used in 'data()' because it is before initialization.`
|
|
657
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
658
|
+
|
|
659
|
+
错误示例:
|
|
660
|
+
|
|
661
|
+
<!-- prettier-ignore -->
|
|
662
|
+
````vue
|
|
663
|
+
<script>
|
|
664
|
+
export default { data() { return { label: this.fullName }; }, computed: { fullName() { return this.name.trim(); } } };
|
|
665
|
+
</script>
|
|
666
|
+
````
|
|
667
|
+
|
|
668
|
+
正确示例:
|
|
669
|
+
|
|
670
|
+
<!-- prettier-ignore -->
|
|
671
|
+
````vue
|
|
672
|
+
<script>
|
|
673
|
+
export default { data: () => ({ name: '' }), computed: { fullName() { return this.name.trim(); } } };
|
|
674
|
+
</script>
|
|
675
|
+
````
|
|
676
|
+
|
|
677
|
+
### `vue/no-deprecated-data-object-declaration`
|
|
678
|
+
|
|
679
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated object declaration on data (in Vue.js 3.0.0+)
|
|
680
|
+
|
|
681
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
682
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
683
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-data-object-declaration.html)
|
|
684
|
+
- 常见报告:`Object declaration on 'data' property is deprecated. Using function declaration instead.`
|
|
685
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
686
|
+
|
|
687
|
+
错误示例:
|
|
688
|
+
|
|
689
|
+
<!-- prettier-ignore -->
|
|
690
|
+
````vue
|
|
691
|
+
<script>
|
|
692
|
+
export default { data: { ready: false } };
|
|
693
|
+
</script>
|
|
694
|
+
````
|
|
695
|
+
|
|
696
|
+
正确示例:
|
|
697
|
+
|
|
698
|
+
<!-- prettier-ignore -->
|
|
699
|
+
````vue
|
|
700
|
+
<script>
|
|
701
|
+
export default { data() { return { ready: false }; } };
|
|
702
|
+
</script>
|
|
703
|
+
````
|
|
704
|
+
|
|
705
|
+
### `vue/no-deprecated-delete-set`
|
|
706
|
+
|
|
707
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated `$delete` and `$set` (in Vue.js 3.0.0+)
|
|
708
|
+
|
|
709
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
710
|
+
- 自动修复:不支持或上游未声明
|
|
711
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-delete-set.html)
|
|
712
|
+
- 常见报告:`The '$delete', '$set' is deprecated.`
|
|
713
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
714
|
+
|
|
715
|
+
错误示例:
|
|
716
|
+
|
|
717
|
+
<!-- prettier-ignore -->
|
|
718
|
+
````vue
|
|
719
|
+
<script>
|
|
720
|
+
export default { methods: { update() { this.$set(this.user, 'name', 'Fast'); this.$delete(this.user, 'legacy'); } } };
|
|
721
|
+
</script>
|
|
722
|
+
````
|
|
723
|
+
|
|
724
|
+
正确示例:
|
|
725
|
+
|
|
726
|
+
<!-- prettier-ignore -->
|
|
727
|
+
````vue
|
|
728
|
+
<script>
|
|
729
|
+
export default { methods: { update() { this.user.name = 'Fast'; delete this.user.legacy; } } };
|
|
730
|
+
</script>
|
|
731
|
+
````
|
|
732
|
+
|
|
733
|
+
### `vue/no-deprecated-destroyed-lifecycle`
|
|
734
|
+
|
|
735
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated `destroyed` and `beforeDestroy` lifecycle hooks (in Vue.js 3.0.0+)
|
|
736
|
+
|
|
737
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
738
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
739
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-destroyed-lifecycle.html)
|
|
740
|
+
- 常见报告:`The 'destroyed' lifecycle hook is deprecated. Use 'unmounted' instead.`;`The 'beforeDestroy' lifecycle hook is deprecated. Use 'beforeUnmount' instead.`
|
|
741
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
742
|
+
|
|
743
|
+
错误示例:
|
|
744
|
+
|
|
745
|
+
<!-- prettier-ignore -->
|
|
746
|
+
````vue
|
|
747
|
+
<script>
|
|
748
|
+
export default { destroyed() { cleanup(); } };
|
|
749
|
+
</script>
|
|
750
|
+
````
|
|
751
|
+
|
|
752
|
+
正确示例:
|
|
753
|
+
|
|
754
|
+
<!-- prettier-ignore -->
|
|
755
|
+
````vue
|
|
756
|
+
<script>
|
|
757
|
+
export default { unmounted() { cleanup(); } };
|
|
758
|
+
</script>
|
|
759
|
+
````
|
|
760
|
+
|
|
761
|
+
### `vue/no-deprecated-dollar-listeners-api`
|
|
762
|
+
|
|
763
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated `$listeners` (in Vue.js 3.0.0+)
|
|
764
|
+
|
|
765
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
766
|
+
- 自动修复:不支持或上游未声明
|
|
767
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-dollar-listeners-api.html)
|
|
768
|
+
- 常见报告:`The '$listeners' is deprecated.`
|
|
769
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
770
|
+
|
|
771
|
+
错误示例:
|
|
772
|
+
|
|
773
|
+
<!-- prettier-ignore -->
|
|
774
|
+
````vue
|
|
775
|
+
<script>
|
|
776
|
+
export default { mounted() { use(this.$listeners); } };
|
|
777
|
+
</script>
|
|
778
|
+
````
|
|
779
|
+
|
|
780
|
+
正确示例:
|
|
781
|
+
|
|
782
|
+
<!-- prettier-ignore -->
|
|
783
|
+
````vue
|
|
784
|
+
<script>
|
|
785
|
+
export default { mounted() { use(this.$attrs); } };
|
|
786
|
+
</script>
|
|
787
|
+
````
|
|
788
|
+
|
|
789
|
+
### `vue/no-deprecated-dollar-scopedslots-api`
|
|
790
|
+
|
|
791
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated `$scopedSlots` (in Vue.js 3.0.0+)
|
|
792
|
+
|
|
793
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
794
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
795
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-dollar-scopedslots-api.html)
|
|
796
|
+
- 常见报告:`The '$scopedSlots' is deprecated.`
|
|
797
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
798
|
+
|
|
799
|
+
错误示例:
|
|
800
|
+
|
|
801
|
+
<!-- prettier-ignore -->
|
|
802
|
+
````vue
|
|
803
|
+
<script>
|
|
804
|
+
export default { mounted() { use(this.$scopedSlots); } };
|
|
805
|
+
</script>
|
|
806
|
+
````
|
|
807
|
+
|
|
808
|
+
正确示例:
|
|
809
|
+
|
|
810
|
+
<!-- prettier-ignore -->
|
|
811
|
+
````vue
|
|
812
|
+
<script>
|
|
813
|
+
export default { mounted() { use(this.$slots); } };
|
|
814
|
+
</script>
|
|
815
|
+
````
|
|
816
|
+
|
|
817
|
+
### `vue/no-deprecated-events-api`
|
|
818
|
+
|
|
819
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated events api (in Vue.js 3.0.0+)
|
|
820
|
+
|
|
821
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
822
|
+
- 自动修复:不支持或上游未声明
|
|
823
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-events-api.html)
|
|
824
|
+
- 常见报告:`The Events api '$on', '$off' '$once' is deprecated. Using external library instead, for example mitt.`
|
|
825
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
826
|
+
|
|
827
|
+
错误示例:
|
|
828
|
+
|
|
829
|
+
<!-- prettier-ignore -->
|
|
830
|
+
````vue
|
|
831
|
+
<script>
|
|
832
|
+
export default { mounted() { this.$on('save', this.handleSave); } };
|
|
833
|
+
</script>
|
|
834
|
+
````
|
|
835
|
+
|
|
836
|
+
正确示例:
|
|
837
|
+
|
|
838
|
+
<!-- prettier-ignore -->
|
|
839
|
+
````vue
|
|
840
|
+
<script>
|
|
841
|
+
export default { mounted() { eventBus.on('save', this.handleSave); } };
|
|
842
|
+
</script>
|
|
843
|
+
````
|
|
844
|
+
|
|
845
|
+
### `vue/no-deprecated-filter`
|
|
846
|
+
|
|
847
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated filters syntax (in Vue.js 3.0.0+)
|
|
848
|
+
|
|
849
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
850
|
+
- 自动修复:不支持或上游未声明
|
|
851
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-filter.html)
|
|
852
|
+
- 常见报告:`Filters are deprecated.`
|
|
853
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
854
|
+
|
|
855
|
+
错误示例:
|
|
856
|
+
|
|
857
|
+
<!-- prettier-ignore -->
|
|
858
|
+
````vue
|
|
859
|
+
<template>
|
|
860
|
+
<p>{{ total | currency }}</p>
|
|
861
|
+
</template>
|
|
862
|
+
````
|
|
863
|
+
|
|
864
|
+
正确示例:
|
|
865
|
+
|
|
866
|
+
<!-- prettier-ignore -->
|
|
867
|
+
````vue
|
|
868
|
+
<template>
|
|
869
|
+
<p>{{ formatCurrency(total) }}</p>
|
|
870
|
+
</template>
|
|
871
|
+
````
|
|
872
|
+
|
|
873
|
+
### `vue/no-deprecated-functional-template`
|
|
874
|
+
|
|
875
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated the `functional` template (in Vue.js 3.0.0+)
|
|
876
|
+
|
|
877
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
878
|
+
- 自动修复:不支持或上游未声明
|
|
879
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-functional-template.html)
|
|
880
|
+
- 常见报告:`The 'functional' template are deprecated.`
|
|
881
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
882
|
+
|
|
883
|
+
错误示例:
|
|
884
|
+
|
|
885
|
+
<!-- prettier-ignore -->
|
|
886
|
+
````vue
|
|
887
|
+
<template functional><div /></template>
|
|
888
|
+
````
|
|
889
|
+
|
|
890
|
+
正确示例:
|
|
891
|
+
|
|
892
|
+
<!-- prettier-ignore -->
|
|
893
|
+
````vue
|
|
894
|
+
<script>export default (props) => h('div', props);</script>
|
|
895
|
+
````
|
|
896
|
+
|
|
897
|
+
### `vue/no-deprecated-html-element-is`
|
|
898
|
+
|
|
899
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated the `is` attribute on HTML elements (in Vue.js 3.0.0+)
|
|
900
|
+
|
|
901
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
902
|
+
- 自动修复:不支持或上游未声明
|
|
903
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-html-element-is.html)
|
|
904
|
+
- 常见报告:`The 'is' attribute on HTML element are deprecated.`
|
|
905
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
906
|
+
|
|
907
|
+
错误示例:
|
|
908
|
+
|
|
909
|
+
<!-- prettier-ignore -->
|
|
910
|
+
````vue
|
|
911
|
+
<template>
|
|
912
|
+
<table><tr is="UserRow" /></table>
|
|
913
|
+
</template>
|
|
914
|
+
````
|
|
915
|
+
|
|
916
|
+
正确示例:
|
|
917
|
+
|
|
918
|
+
<!-- prettier-ignore -->
|
|
919
|
+
````vue
|
|
920
|
+
<template>
|
|
921
|
+
<table><tr is="vue:UserRow" /></table>
|
|
922
|
+
</template>
|
|
923
|
+
````
|
|
924
|
+
|
|
925
|
+
### `vue/no-deprecated-inline-template`
|
|
926
|
+
|
|
927
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated `inline-template` attribute (in Vue.js 3.0.0+)
|
|
928
|
+
|
|
929
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
930
|
+
- 自动修复:不支持或上游未声明
|
|
931
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-inline-template.html)
|
|
932
|
+
- 常见报告:`'inline-template' are deprecated.`
|
|
933
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
934
|
+
|
|
935
|
+
错误示例:
|
|
936
|
+
|
|
937
|
+
<!-- prettier-ignore -->
|
|
938
|
+
````vue
|
|
939
|
+
<template>
|
|
940
|
+
<UserCard inline-template><p>{{ name }}</p></UserCard>
|
|
941
|
+
</template>
|
|
942
|
+
````
|
|
943
|
+
|
|
944
|
+
正确示例:
|
|
945
|
+
|
|
946
|
+
<!-- prettier-ignore -->
|
|
947
|
+
````vue
|
|
948
|
+
<template>
|
|
949
|
+
<UserCard><template #default><p>{{ name }}</p></template></UserCard>
|
|
950
|
+
</template>
|
|
951
|
+
````
|
|
952
|
+
|
|
953
|
+
### `vue/no-deprecated-model-definition`
|
|
954
|
+
|
|
955
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow deprecated `model` definition (in Vue.js 3.0.0+)
|
|
956
|
+
|
|
957
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
958
|
+
- 自动修复:不支持或上游未声明
|
|
959
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-model-definition.html)
|
|
960
|
+
- 常见报告:`'model' definition is deprecated.`;`'model' definition is deprecated. You may use the Vue 3-compatible 'modelValue'/'update:modelValue' though.`;`Change to 'modelValue'/'update:modelValue'.`
|
|
961
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
962
|
+
|
|
963
|
+
错误示例:
|
|
964
|
+
|
|
965
|
+
<!-- prettier-ignore -->
|
|
966
|
+
````vue
|
|
967
|
+
<script>
|
|
968
|
+
export default { model: { prop: 'value', event: 'input' } };
|
|
969
|
+
</script>
|
|
970
|
+
````
|
|
971
|
+
|
|
972
|
+
正确示例:
|
|
973
|
+
|
|
974
|
+
<!-- prettier-ignore -->
|
|
975
|
+
````vue
|
|
976
|
+
<script>
|
|
977
|
+
export default { props: { modelValue: String }, emits: ['update:modelValue'] };
|
|
978
|
+
</script>
|
|
979
|
+
````
|
|
980
|
+
|
|
981
|
+
### `vue/no-deprecated-props-default-this`
|
|
982
|
+
|
|
983
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow deprecated `this` access in props default function (in Vue.js 3.0.0+)
|
|
984
|
+
|
|
985
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
986
|
+
- 自动修复:不支持或上游未声明
|
|
987
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-props-default-this.html)
|
|
988
|
+
- 常见报告:`Props default value factory functions no longer have access to 'this'.`
|
|
989
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
990
|
+
|
|
991
|
+
错误示例:
|
|
992
|
+
|
|
993
|
+
<!-- prettier-ignore -->
|
|
994
|
+
````vue
|
|
995
|
+
<script>
|
|
996
|
+
export default { props: { color: { default() { return this.theme.color; } } } };
|
|
997
|
+
</script>
|
|
998
|
+
````
|
|
999
|
+
|
|
1000
|
+
正确示例:
|
|
1001
|
+
|
|
1002
|
+
<!-- prettier-ignore -->
|
|
1003
|
+
````vue
|
|
1004
|
+
<script>
|
|
1005
|
+
export default { props: { color: { default: 'blue' } } };
|
|
1006
|
+
</script>
|
|
1007
|
+
````
|
|
1008
|
+
|
|
1009
|
+
### `vue/no-deprecated-router-link-tag-prop`
|
|
1010
|
+
|
|
1011
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated `tag` property on `RouterLink` (in Vue.js 3.0.0+)
|
|
1012
|
+
|
|
1013
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1014
|
+
- 自动修复:不支持或上游未声明
|
|
1015
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-router-link-tag-prop.html)
|
|
1016
|
+
- 常见报告:`'tag' property on '{{element}}' component is deprecated. Use scoped slots instead.`
|
|
1017
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1018
|
+
|
|
1019
|
+
错误示例:
|
|
1020
|
+
|
|
1021
|
+
<!-- prettier-ignore -->
|
|
1022
|
+
````vue
|
|
1023
|
+
<template>
|
|
1024
|
+
<RouterLink to="/home" tag="button">Home</RouterLink>
|
|
1025
|
+
</template>
|
|
1026
|
+
````
|
|
1027
|
+
|
|
1028
|
+
正确示例:
|
|
1029
|
+
|
|
1030
|
+
<!-- prettier-ignore -->
|
|
1031
|
+
````vue
|
|
1032
|
+
<template>
|
|
1033
|
+
<RouterLink to="/home" custom v-slot="{ navigate }"><button @click="navigate">Home</button></RouterLink>
|
|
1034
|
+
</template>
|
|
1035
|
+
````
|
|
1036
|
+
|
|
1037
|
+
### `vue/no-deprecated-scope-attribute`
|
|
1038
|
+
|
|
1039
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow deprecated `scope` attribute (in Vue.js 2.5.0+)
|
|
1040
|
+
|
|
1041
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1042
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
1043
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-scope-attribute.html)
|
|
1044
|
+
- 常见报告:`'scope' attributes are deprecated.`
|
|
1045
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1046
|
+
|
|
1047
|
+
错误示例:
|
|
1048
|
+
|
|
1049
|
+
<!-- prettier-ignore -->
|
|
1050
|
+
````vue
|
|
1051
|
+
<template>
|
|
1052
|
+
<template scope="slotProps">{{ slotProps.name }}</template>
|
|
1053
|
+
</template>
|
|
1054
|
+
````
|
|
1055
|
+
|
|
1056
|
+
正确示例:
|
|
1057
|
+
|
|
1058
|
+
<!-- prettier-ignore -->
|
|
1059
|
+
````vue
|
|
1060
|
+
<template>
|
|
1061
|
+
<template #default="slotProps">{{ slotProps.name }}</template>
|
|
1062
|
+
</template>
|
|
1063
|
+
````
|
|
1064
|
+
|
|
1065
|
+
### `vue/no-deprecated-slot-attribute`
|
|
1066
|
+
|
|
1067
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow deprecated `slot` attribute (in Vue.js 2.6.0+)
|
|
1068
|
+
|
|
1069
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1070
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
1071
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-slot-attribute.html)
|
|
1072
|
+
- 常见报告:`'slot' attributes are deprecated.`
|
|
1073
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1074
|
+
|
|
1075
|
+
错误示例:
|
|
1076
|
+
|
|
1077
|
+
<!-- prettier-ignore -->
|
|
1078
|
+
````vue
|
|
1079
|
+
<template>
|
|
1080
|
+
<p slot="header">Title</p>
|
|
1081
|
+
</template>
|
|
1082
|
+
````
|
|
1083
|
+
|
|
1084
|
+
正确示例:
|
|
1085
|
+
|
|
1086
|
+
<!-- prettier-ignore -->
|
|
1087
|
+
````vue
|
|
1088
|
+
<template>
|
|
1089
|
+
<template #header><p>Title</p></template>
|
|
1090
|
+
</template>
|
|
1091
|
+
````
|
|
1092
|
+
|
|
1093
|
+
### `vue/no-deprecated-slot-scope-attribute`
|
|
1094
|
+
|
|
1095
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow deprecated `slot-scope` attribute (in Vue.js 2.6.0+)
|
|
1096
|
+
|
|
1097
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1098
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
1099
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-slot-scope-attribute.html)
|
|
1100
|
+
- 常见报告:`'slot-scope' are deprecated.`
|
|
1101
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1102
|
+
|
|
1103
|
+
错误示例:
|
|
1104
|
+
|
|
1105
|
+
<!-- prettier-ignore -->
|
|
1106
|
+
````vue
|
|
1107
|
+
<template>
|
|
1108
|
+
<template slot-scope="slotProps">{{ slotProps.name }}</template>
|
|
1109
|
+
</template>
|
|
1110
|
+
````
|
|
1111
|
+
|
|
1112
|
+
正确示例:
|
|
1113
|
+
|
|
1114
|
+
<!-- prettier-ignore -->
|
|
1115
|
+
````vue
|
|
1116
|
+
<template>
|
|
1117
|
+
<template #default="slotProps">{{ slotProps.name }}</template>
|
|
1118
|
+
</template>
|
|
1119
|
+
````
|
|
1120
|
+
|
|
1121
|
+
### `vue/no-deprecated-v-bind-sync`
|
|
1122
|
+
|
|
1123
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+)
|
|
1124
|
+
|
|
1125
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1126
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
1127
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-v-bind-sync.html)
|
|
1128
|
+
- 常见报告:`'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead.`
|
|
1129
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1130
|
+
|
|
1131
|
+
错误示例:
|
|
1132
|
+
|
|
1133
|
+
<!-- prettier-ignore -->
|
|
1134
|
+
````vue
|
|
1135
|
+
<template>
|
|
1136
|
+
<UserCard :name.sync="name" />
|
|
1137
|
+
</template>
|
|
1138
|
+
````
|
|
1139
|
+
|
|
1140
|
+
正确示例:
|
|
1141
|
+
|
|
1142
|
+
<!-- prettier-ignore -->
|
|
1143
|
+
````vue
|
|
1144
|
+
<template>
|
|
1145
|
+
<UserCard v-model:name="name" />
|
|
1146
|
+
</template>
|
|
1147
|
+
````
|
|
1148
|
+
|
|
1149
|
+
### `vue/no-deprecated-v-is`
|
|
1150
|
+
|
|
1151
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow deprecated `v-is` directive (in Vue.js 3.1.0+)
|
|
1152
|
+
|
|
1153
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1154
|
+
- 自动修复:不支持或上游未声明
|
|
1155
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-v-is.html)
|
|
1156
|
+
- 常见报告:`'v-is' directive is deprecated.`
|
|
1157
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1158
|
+
|
|
1159
|
+
错误示例:
|
|
1160
|
+
|
|
1161
|
+
<!-- prettier-ignore -->
|
|
1162
|
+
````vue
|
|
1163
|
+
<template>
|
|
1164
|
+
<div v-is="componentName" />
|
|
1165
|
+
</template>
|
|
1166
|
+
````
|
|
1167
|
+
|
|
1168
|
+
正确示例:
|
|
1169
|
+
|
|
1170
|
+
<!-- prettier-ignore -->
|
|
1171
|
+
````vue
|
|
1172
|
+
<template>
|
|
1173
|
+
<component :is="componentName" />
|
|
1174
|
+
</template>
|
|
1175
|
+
````
|
|
1176
|
+
|
|
1177
|
+
### `vue/no-deprecated-v-on-native-modifier`
|
|
1178
|
+
|
|
1179
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated `.native` modifiers (in Vue.js 3.0.0+)
|
|
1180
|
+
|
|
1181
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1182
|
+
- 自动修复:不支持或上游未声明
|
|
1183
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-v-on-native-modifier.html)
|
|
1184
|
+
- 常见报告:`'.native' modifier on 'v-on' directive is deprecated.`
|
|
1185
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1186
|
+
|
|
1187
|
+
错误示例:
|
|
1188
|
+
|
|
1189
|
+
<!-- prettier-ignore -->
|
|
1190
|
+
````vue
|
|
1191
|
+
<template>
|
|
1192
|
+
<UserCard @click.native="open" />
|
|
1193
|
+
</template>
|
|
1194
|
+
````
|
|
1195
|
+
|
|
1196
|
+
正确示例:
|
|
1197
|
+
|
|
1198
|
+
<!-- prettier-ignore -->
|
|
1199
|
+
````vue
|
|
1200
|
+
<template>
|
|
1201
|
+
<UserCard @click="open" />
|
|
1202
|
+
</template>
|
|
1203
|
+
````
|
|
1204
|
+
|
|
1205
|
+
### `vue/no-deprecated-v-on-number-modifiers`
|
|
1206
|
+
|
|
1207
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated number (keycode) modifiers (in Vue.js 3.0.0+)
|
|
1208
|
+
|
|
1209
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1210
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
1211
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-v-on-number-modifiers.html)
|
|
1212
|
+
- 常见报告:`'KeyboardEvent.keyCode' modifier on 'v-on' directive is deprecated. Using 'KeyboardEvent.key' instead.`
|
|
1213
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1214
|
+
|
|
1215
|
+
错误示例:
|
|
1216
|
+
|
|
1217
|
+
<!-- prettier-ignore -->
|
|
1218
|
+
````vue
|
|
1219
|
+
<template>
|
|
1220
|
+
<input @keyup.13="submit" />
|
|
1221
|
+
</template>
|
|
1222
|
+
````
|
|
1223
|
+
|
|
1224
|
+
正确示例:
|
|
1225
|
+
|
|
1226
|
+
<!-- prettier-ignore -->
|
|
1227
|
+
````vue
|
|
1228
|
+
<template>
|
|
1229
|
+
<input @keyup.enter="submit" />
|
|
1230
|
+
</template>
|
|
1231
|
+
````
|
|
1232
|
+
|
|
1233
|
+
### `vue/no-deprecated-vue-config-keycodes`
|
|
1234
|
+
|
|
1235
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using deprecated `Vue.config.keyCodes` (in Vue.js 3.0.0+)
|
|
1236
|
+
|
|
1237
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1238
|
+
- 自动修复:不支持或上游未声明
|
|
1239
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-deprecated-vue-config-keycodes.html)
|
|
1240
|
+
- 常见报告:`'Vue.config.keyCodes' are deprecated.`
|
|
1241
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1242
|
+
|
|
1243
|
+
错误示例:
|
|
1244
|
+
|
|
1245
|
+
<!-- prettier-ignore -->
|
|
1246
|
+
````vue
|
|
1247
|
+
<script>
|
|
1248
|
+
Vue.config.keyCodes.f1 = 112;
|
|
1249
|
+
</script>
|
|
1250
|
+
````
|
|
1251
|
+
|
|
1252
|
+
正确示例:
|
|
1253
|
+
|
|
1254
|
+
<!-- prettier-ignore -->
|
|
1255
|
+
````vue
|
|
1256
|
+
<script>
|
|
1257
|
+
const onKeydown = (event) => { if (event.key === 'F1') openHelp(); };
|
|
1258
|
+
</script>
|
|
1259
|
+
````
|
|
1260
|
+
|
|
1261
|
+
### `vue/no-dupe-v-else-if`
|
|
1262
|
+
|
|
1263
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow duplicate conditions in `v-if` / `v-else-if` chains
|
|
1264
|
+
|
|
1265
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1266
|
+
- 自动修复:不支持或上游未声明
|
|
1267
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-dupe-v-else-if.html)
|
|
1268
|
+
- 常见报告:`This branch can never execute. Its condition is a duplicate or covered by previous conditions in the 'v-if' / 'v-else-if' chain.`
|
|
1269
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1270
|
+
|
|
1271
|
+
错误示例:
|
|
1272
|
+
|
|
1273
|
+
<!-- prettier-ignore -->
|
|
1274
|
+
````vue
|
|
1275
|
+
<template>
|
|
1276
|
+
<p v-if="status === 'ready'">Ready</p><p v-else-if="status === 'ready'">Again</p>
|
|
1277
|
+
</template>
|
|
1278
|
+
````
|
|
1279
|
+
|
|
1280
|
+
正确示例:
|
|
1281
|
+
|
|
1282
|
+
<!-- prettier-ignore -->
|
|
1283
|
+
````vue
|
|
1284
|
+
<template>
|
|
1285
|
+
<p v-if="status === 'ready'">Ready</p><p v-else-if="status === 'failed'">Failed</p>
|
|
1286
|
+
</template>
|
|
1287
|
+
````
|
|
1288
|
+
|
|
1289
|
+
### `vue/no-duplicate-attributes`
|
|
1290
|
+
|
|
1291
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow duplication of attributes
|
|
1292
|
+
|
|
1293
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1294
|
+
- 自动修复:不支持或上游未声明
|
|
1295
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-duplicate-attributes.html)
|
|
1296
|
+
- 常见报告:`Duplicate attribute '{{name}}'.`
|
|
1297
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1298
|
+
|
|
1299
|
+
错误示例:
|
|
1300
|
+
|
|
1301
|
+
<!-- prettier-ignore -->
|
|
1302
|
+
````vue
|
|
1303
|
+
<template>
|
|
1304
|
+
<UserCard name="A" name="B" />
|
|
1305
|
+
</template>
|
|
1306
|
+
````
|
|
1307
|
+
|
|
1308
|
+
正确示例:
|
|
1309
|
+
|
|
1310
|
+
<!-- prettier-ignore -->
|
|
1311
|
+
````vue
|
|
1312
|
+
<template>
|
|
1313
|
+
<UserCard first-name="A" last-name="B" />
|
|
1314
|
+
</template>
|
|
1315
|
+
````
|
|
1316
|
+
|
|
1317
|
+
### `vue/no-export-in-script-setup`
|
|
1318
|
+
|
|
1319
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow `export` in `<script setup>`
|
|
1320
|
+
|
|
1321
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1322
|
+
- 自动修复:不支持或上游未声明
|
|
1323
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-export-in-script-setup.html)
|
|
1324
|
+
- 常见报告:`'<script setup>' cannot contain ES module exports.`
|
|
1325
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1326
|
+
|
|
1327
|
+
错误示例:
|
|
1328
|
+
|
|
1329
|
+
<!-- prettier-ignore -->
|
|
1330
|
+
````vue
|
|
1331
|
+
<script setup>export const ready = true;</script>
|
|
1332
|
+
````
|
|
1333
|
+
|
|
1334
|
+
正确示例:
|
|
1335
|
+
|
|
1336
|
+
<!-- prettier-ignore -->
|
|
1337
|
+
````vue
|
|
1338
|
+
<script setup>const ready = true;</script>
|
|
1339
|
+
````
|
|
1340
|
+
|
|
1341
|
+
### `vue/no-expose-after-await`
|
|
1342
|
+
|
|
1343
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow asynchronously registered `expose`
|
|
1344
|
+
|
|
1345
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1346
|
+
- 自动修复:不支持或上游未声明
|
|
1347
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-expose-after-await.html)
|
|
1348
|
+
- 常见报告:`'{{name}}' is forbidden after an 'await' expression.`
|
|
1349
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1350
|
+
|
|
1351
|
+
错误示例:
|
|
1352
|
+
|
|
1353
|
+
<!-- prettier-ignore -->
|
|
1354
|
+
````vue
|
|
1355
|
+
<script setup>await load();
|
|
1356
|
+
defineExpose({ refresh });</script>
|
|
1357
|
+
````
|
|
1358
|
+
|
|
1359
|
+
正确示例:
|
|
1360
|
+
|
|
1361
|
+
<!-- prettier-ignore -->
|
|
1362
|
+
````vue
|
|
1363
|
+
<script setup>defineExpose({ refresh });
|
|
1364
|
+
await load();</script>
|
|
1365
|
+
````
|
|
1366
|
+
|
|
1367
|
+
### `vue/no-lifecycle-after-await`
|
|
1368
|
+
|
|
1369
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow asynchronously registered lifecycle hooks
|
|
1370
|
+
|
|
1371
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1372
|
+
- 自动修复:不支持或上游未声明
|
|
1373
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-lifecycle-after-await.html)
|
|
1374
|
+
- 常见报告:`Lifecycle hooks are forbidden after an 'await' expression.`
|
|
1375
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1376
|
+
|
|
1377
|
+
错误示例:
|
|
1378
|
+
|
|
1379
|
+
<!-- prettier-ignore -->
|
|
1380
|
+
````vue
|
|
1381
|
+
<script>import { onMounted } from 'vue';
|
|
1382
|
+
export default { async setup() { await load(); onMounted(start); } };</script>
|
|
1383
|
+
````
|
|
1384
|
+
|
|
1385
|
+
正确示例:
|
|
1386
|
+
|
|
1387
|
+
<!-- prettier-ignore -->
|
|
1388
|
+
````vue
|
|
1389
|
+
<script>import { onMounted } from 'vue';
|
|
1390
|
+
export default { async setup() { onMounted(start); await load(); } };</script>
|
|
1391
|
+
````
|
|
1392
|
+
|
|
1393
|
+
### `vue/no-lone-template`
|
|
1394
|
+
|
|
1395
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow unnecessary `<template>`
|
|
1396
|
+
|
|
1397
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
1398
|
+
- 自动修复:不支持或上游未声明
|
|
1399
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-lone-template.html)
|
|
1400
|
+
- 常见报告:`'<template>' require directive.`
|
|
1401
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1402
|
+
|
|
1403
|
+
错误示例:
|
|
1404
|
+
|
|
1405
|
+
<!-- prettier-ignore -->
|
|
1406
|
+
````vue
|
|
1407
|
+
<template><template><p>Content</p></template></template>
|
|
1408
|
+
````
|
|
1409
|
+
|
|
1410
|
+
正确示例:
|
|
1411
|
+
|
|
1412
|
+
<!-- prettier-ignore -->
|
|
1413
|
+
````vue
|
|
1414
|
+
<template><p>Content</p></template>
|
|
1415
|
+
````
|
|
1416
|
+
|
|
1417
|
+
### `vue/no-multiple-slot-args`
|
|
1418
|
+
|
|
1419
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow passing multiple arguments to scoped slots
|
|
1420
|
+
|
|
1421
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
1422
|
+
- 自动修复:不支持或上游未声明
|
|
1423
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-multiple-slot-args.html)
|
|
1424
|
+
- 常见报告:`Unexpected multiple arguments.`;`Unexpected spread argument.`
|
|
1425
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1426
|
+
|
|
1427
|
+
错误示例:
|
|
1428
|
+
|
|
1429
|
+
<!-- prettier-ignore -->
|
|
1430
|
+
````vue
|
|
1431
|
+
<script>
|
|
1432
|
+
export default { mounted() { this.$slots.default({ name: 'Fast' }, 0); } };
|
|
1433
|
+
</script>
|
|
1434
|
+
````
|
|
1435
|
+
|
|
1436
|
+
正确示例:
|
|
1437
|
+
|
|
1438
|
+
<!-- prettier-ignore -->
|
|
1439
|
+
````vue
|
|
1440
|
+
<script>
|
|
1441
|
+
export default { mounted() { this.$slots.default({ name: 'Fast', index: 0 }); } };
|
|
1442
|
+
</script>
|
|
1443
|
+
````
|
|
1444
|
+
|
|
1445
|
+
### `vue/no-parsing-error`
|
|
1446
|
+
|
|
1447
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow parsing errors in `<template>`
|
|
1448
|
+
|
|
1449
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1450
|
+
- 自动修复:不支持或上游未声明
|
|
1451
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-parsing-error.html)
|
|
1452
|
+
- 常见报告:`Parsing error: {{message}}.`
|
|
1453
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1454
|
+
|
|
1455
|
+
错误示例:
|
|
1456
|
+
|
|
1457
|
+
<!-- prettier-ignore -->
|
|
1458
|
+
````vue
|
|
1459
|
+
<template><div></span></template>
|
|
1460
|
+
````
|
|
1461
|
+
|
|
1462
|
+
正确示例:
|
|
1463
|
+
|
|
1464
|
+
<!-- prettier-ignore -->
|
|
1465
|
+
````vue
|
|
1466
|
+
<template><div /></template>
|
|
1467
|
+
````
|
|
1468
|
+
|
|
1469
|
+
### `vue/no-ref-as-operand`
|
|
1470
|
+
|
|
1471
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow use of value wrapped by `ref()` (Composition API) as an operand
|
|
1472
|
+
|
|
1473
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1474
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
1475
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-ref-as-operand.html)
|
|
1476
|
+
- 常见报告:`Must use '.value' to read or write the value wrapped by '{{method}}()'.`
|
|
1477
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1478
|
+
|
|
1479
|
+
错误示例:
|
|
1480
|
+
|
|
1481
|
+
<!-- prettier-ignore -->
|
|
1482
|
+
````vue
|
|
1483
|
+
<script setup>import { ref } from 'vue';
|
|
1484
|
+
const count = ref(0);
|
|
1485
|
+
const next = count + 1;</script>
|
|
1486
|
+
````
|
|
1487
|
+
|
|
1488
|
+
正确示例:
|
|
1489
|
+
|
|
1490
|
+
<!-- prettier-ignore -->
|
|
1491
|
+
````vue
|
|
1492
|
+
<script setup>import { ref } from 'vue';
|
|
1493
|
+
const count = ref(0);
|
|
1494
|
+
const next = count.value + 1;</script>
|
|
1495
|
+
````
|
|
1496
|
+
|
|
1497
|
+
### `vue/no-required-prop-with-default`
|
|
1498
|
+
|
|
1499
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:enforce props with default values to be optional
|
|
1500
|
+
|
|
1501
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
1502
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
1503
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-required-prop-with-default.html)
|
|
1504
|
+
- 常见报告:`Prop "{{ key }}" should be optional.`;`Change this prop to be optional.`
|
|
1505
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1506
|
+
|
|
1507
|
+
错误示例:
|
|
1508
|
+
|
|
1509
|
+
<!-- prettier-ignore -->
|
|
1510
|
+
````vue
|
|
1511
|
+
<script>
|
|
1512
|
+
export default { props: { name: { type: String, required: true, default: 'Fast' } } };
|
|
1513
|
+
</script>
|
|
1514
|
+
````
|
|
1515
|
+
|
|
1516
|
+
正确示例:
|
|
1517
|
+
|
|
1518
|
+
<!-- prettier-ignore -->
|
|
1519
|
+
````vue
|
|
1520
|
+
<script>
|
|
1521
|
+
export default { props: { name: { type: String, default: 'Fast' } } };
|
|
1522
|
+
</script>
|
|
1523
|
+
````
|
|
1524
|
+
|
|
1525
|
+
### `vue/no-reserved-keys`
|
|
1526
|
+
|
|
1527
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow overwriting reserved keys
|
|
1528
|
+
|
|
1529
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1530
|
+
- 自动修复:不支持或上游未声明
|
|
1531
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-reserved-keys.html)
|
|
1532
|
+
- 常见报告:`Key '{{name}}' is reserved.`;`Keys starting with '_' are reserved in '{{name}}' group.`
|
|
1533
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1534
|
+
|
|
1535
|
+
错误示例:
|
|
1536
|
+
|
|
1537
|
+
<!-- prettier-ignore -->
|
|
1538
|
+
````vue
|
|
1539
|
+
<script>
|
|
1540
|
+
export default { data: () => ({ $el: null }) };
|
|
1541
|
+
</script>
|
|
1542
|
+
````
|
|
1543
|
+
|
|
1544
|
+
正确示例:
|
|
1545
|
+
|
|
1546
|
+
<!-- prettier-ignore -->
|
|
1547
|
+
````vue
|
|
1548
|
+
<script>
|
|
1549
|
+
export default { data: () => ({ element: null }) };
|
|
1550
|
+
</script>
|
|
1551
|
+
````
|
|
1552
|
+
|
|
1553
|
+
### `vue/no-reserved-props`
|
|
1554
|
+
|
|
1555
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow reserved names in props
|
|
1556
|
+
|
|
1557
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1558
|
+
- 自动修复:不支持或上游未声明
|
|
1559
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-reserved-props.html)
|
|
1560
|
+
- 常见报告:`'{{propName}}' is a reserved attribute and cannot be used as props.`
|
|
1561
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1562
|
+
|
|
1563
|
+
错误示例:
|
|
1564
|
+
|
|
1565
|
+
<!-- prettier-ignore -->
|
|
1566
|
+
````vue
|
|
1567
|
+
<script>
|
|
1568
|
+
export default { props: { key: String } };
|
|
1569
|
+
</script>
|
|
1570
|
+
````
|
|
1571
|
+
|
|
1572
|
+
正确示例:
|
|
1573
|
+
|
|
1574
|
+
<!-- prettier-ignore -->
|
|
1575
|
+
````vue
|
|
1576
|
+
<script>
|
|
1577
|
+
export default { props: { itemKey: String } };
|
|
1578
|
+
</script>
|
|
1579
|
+
````
|
|
1580
|
+
|
|
1581
|
+
### `vue/no-shared-component-data`
|
|
1582
|
+
|
|
1583
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:enforce component's data property to be a function
|
|
1584
|
+
|
|
1585
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1586
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
1587
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-shared-component-data.html)
|
|
1588
|
+
- 常见报告:`'data' property in component must be a function.`
|
|
1589
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1590
|
+
|
|
1591
|
+
错误示例:
|
|
1592
|
+
|
|
1593
|
+
<!-- prettier-ignore -->
|
|
1594
|
+
````vue
|
|
1595
|
+
<script>
|
|
1596
|
+
export default { data: { ready: false } };
|
|
1597
|
+
</script>
|
|
1598
|
+
````
|
|
1599
|
+
|
|
1600
|
+
正确示例:
|
|
1601
|
+
|
|
1602
|
+
<!-- prettier-ignore -->
|
|
1603
|
+
````vue
|
|
1604
|
+
<script>
|
|
1605
|
+
export default { data() { return { ready: false }; } };
|
|
1606
|
+
</script>
|
|
1607
|
+
````
|
|
1608
|
+
|
|
1609
|
+
### `vue/no-side-effects-in-computed-properties`
|
|
1610
|
+
|
|
1611
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow side effects in computed properties
|
|
1612
|
+
|
|
1613
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1614
|
+
- 自动修复:不支持或上游未声明
|
|
1615
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-side-effects-in-computed-properties.html)
|
|
1616
|
+
- 常见报告:`Unexpected side effect in computed function.`;`Unexpected side effect in "{{key}}" computed property.`
|
|
1617
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1618
|
+
|
|
1619
|
+
错误示例:
|
|
1620
|
+
|
|
1621
|
+
<!-- prettier-ignore -->
|
|
1622
|
+
````vue
|
|
1623
|
+
<script>
|
|
1624
|
+
export default { computed: { fullName() { this.name = this.name.trim(); return this.name; } } };
|
|
1625
|
+
</script>
|
|
1626
|
+
````
|
|
1627
|
+
|
|
1628
|
+
正确示例:
|
|
1629
|
+
|
|
1630
|
+
<!-- prettier-ignore -->
|
|
1631
|
+
````vue
|
|
1632
|
+
<script>
|
|
1633
|
+
export default { computed: { fullName() { return this.name.trim(); } } };
|
|
1634
|
+
</script>
|
|
1635
|
+
````
|
|
1636
|
+
|
|
1637
|
+
### `vue/no-template-key`
|
|
1638
|
+
|
|
1639
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow `key` attribute on `<template>`
|
|
1640
|
+
|
|
1641
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1642
|
+
- 自动修复:不支持或上游未声明
|
|
1643
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-template-key.html)
|
|
1644
|
+
- 常见报告:`'<template>' cannot be keyed. Place the key on real elements instead.`
|
|
1645
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1646
|
+
|
|
1647
|
+
错误示例:
|
|
1648
|
+
|
|
1649
|
+
<!-- prettier-ignore -->
|
|
1650
|
+
````vue
|
|
1651
|
+
<template>
|
|
1652
|
+
<template :key="item.id"><UserRow /></template>
|
|
1653
|
+
</template>
|
|
1654
|
+
````
|
|
1655
|
+
|
|
1656
|
+
正确示例:
|
|
1657
|
+
|
|
1658
|
+
<!-- prettier-ignore -->
|
|
1659
|
+
````vue
|
|
1660
|
+
<template>
|
|
1661
|
+
<UserRow :key="item.id" />
|
|
1662
|
+
</template>
|
|
1663
|
+
````
|
|
1664
|
+
|
|
1665
|
+
### `vue/no-template-shadow`
|
|
1666
|
+
|
|
1667
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow variable declarations from shadowing variables declared in the outer scope
|
|
1668
|
+
|
|
1669
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
1670
|
+
- 自动修复:不支持或上游未声明
|
|
1671
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-template-shadow.html)
|
|
1672
|
+
- 常见报告:`Variable '{{name}}' is already declared in the upper scope.`
|
|
1673
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1674
|
+
|
|
1675
|
+
错误示例:
|
|
1676
|
+
|
|
1677
|
+
<!-- prettier-ignore -->
|
|
1678
|
+
````vue
|
|
1679
|
+
<template>
|
|
1680
|
+
<div v-for="user in users"><span v-for="user in user.friends">{{ user.name }}</span></div>
|
|
1681
|
+
</template>
|
|
1682
|
+
````
|
|
1683
|
+
|
|
1684
|
+
正确示例:
|
|
1685
|
+
|
|
1686
|
+
<!-- prettier-ignore -->
|
|
1687
|
+
````vue
|
|
1688
|
+
<template>
|
|
1689
|
+
<div v-for="user in users"><span v-for="friend in user.friends">{{ friend.name }}</span></div>
|
|
1690
|
+
</template>
|
|
1691
|
+
````
|
|
1692
|
+
|
|
1693
|
+
### `vue/no-textarea-mustache`
|
|
1694
|
+
|
|
1695
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow mustaches in `<textarea>`
|
|
1696
|
+
|
|
1697
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1698
|
+
- 自动修复:不支持或上游未声明
|
|
1699
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-textarea-mustache.html)
|
|
1700
|
+
- 常见报告:`Unexpected mustache. Use 'v-model' instead.`
|
|
1701
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1702
|
+
|
|
1703
|
+
错误示例:
|
|
1704
|
+
|
|
1705
|
+
<!-- prettier-ignore -->
|
|
1706
|
+
````vue
|
|
1707
|
+
<template>
|
|
1708
|
+
<textarea>{{ message }}</textarea>
|
|
1709
|
+
</template>
|
|
1710
|
+
````
|
|
1711
|
+
|
|
1712
|
+
正确示例:
|
|
1713
|
+
|
|
1714
|
+
<!-- prettier-ignore -->
|
|
1715
|
+
````vue
|
|
1716
|
+
<template>
|
|
1717
|
+
<textarea v-model="message" />
|
|
1718
|
+
</template>
|
|
1719
|
+
````
|
|
1720
|
+
|
|
1721
|
+
### `vue/no-unused-components`
|
|
1722
|
+
|
|
1723
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow registering components that are not used inside templates
|
|
1724
|
+
|
|
1725
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1726
|
+
- 自动修复:不支持或上游未声明
|
|
1727
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-unused-components.html)
|
|
1728
|
+
- 常见报告:`The "{{name}}" component has been registered but not used.`
|
|
1729
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1730
|
+
|
|
1731
|
+
错误示例:
|
|
1732
|
+
|
|
1733
|
+
<!-- prettier-ignore -->
|
|
1734
|
+
````vue
|
|
1735
|
+
<script>import UserCard from './UserCard.vue';
|
|
1736
|
+
export default { components: { UserCard } };</script>
|
|
1737
|
+
<template><div /></template>
|
|
1738
|
+
````
|
|
1739
|
+
|
|
1740
|
+
正确示例:
|
|
1741
|
+
|
|
1742
|
+
<!-- prettier-ignore -->
|
|
1743
|
+
````vue
|
|
1744
|
+
<script>import UserCard from './UserCard.vue';
|
|
1745
|
+
export default { components: { UserCard } };</script>
|
|
1746
|
+
<template><UserCard /></template>
|
|
1747
|
+
````
|
|
1748
|
+
|
|
1749
|
+
### `vue/no-unused-vars`
|
|
1750
|
+
|
|
1751
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow unused variable definitions of v-for directives or scope attributes
|
|
1752
|
+
|
|
1753
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1754
|
+
- 自动修复:不支持或上游未声明
|
|
1755
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-unused-vars.html)
|
|
1756
|
+
- 常见报告:`'{{name}}' is defined but never used.`;`Replace '{{name}}' with '_{{name}}' to ignore the unused variable.`
|
|
1757
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1758
|
+
|
|
1759
|
+
错误示例:
|
|
1760
|
+
|
|
1761
|
+
<!-- prettier-ignore -->
|
|
1762
|
+
````vue
|
|
1763
|
+
<template>
|
|
1764
|
+
<li v-for="item in items">Static</li>
|
|
1765
|
+
</template>
|
|
1766
|
+
````
|
|
1767
|
+
|
|
1768
|
+
正确示例:
|
|
1769
|
+
|
|
1770
|
+
<!-- prettier-ignore -->
|
|
1771
|
+
````vue
|
|
1772
|
+
<template>
|
|
1773
|
+
<li v-for="item in items">{{ item.name }}</li>
|
|
1774
|
+
</template>
|
|
1775
|
+
````
|
|
1776
|
+
|
|
1777
|
+
### `vue/no-use-computed-property-like-method`
|
|
1778
|
+
|
|
1779
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow use computed property like method
|
|
1780
|
+
|
|
1781
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1782
|
+
- 自动修复:不支持或上游未声明
|
|
1783
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-use-computed-property-like-method.html)
|
|
1784
|
+
- 常见报告:`Use {{ likeProperty }} instead of {{ likeMethod }}.`
|
|
1785
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1786
|
+
|
|
1787
|
+
错误示例:
|
|
1788
|
+
|
|
1789
|
+
<!-- prettier-ignore -->
|
|
1790
|
+
````vue
|
|
1791
|
+
<script>
|
|
1792
|
+
export default { computed: { fullName() { return 'Fast'; } }, mounted() { use(this.fullName()); } };
|
|
1793
|
+
</script>
|
|
1794
|
+
````
|
|
1795
|
+
|
|
1796
|
+
正确示例:
|
|
1797
|
+
|
|
1798
|
+
<!-- prettier-ignore -->
|
|
1799
|
+
````vue
|
|
1800
|
+
<script>
|
|
1801
|
+
export default { computed: { fullName() { return 'Fast'; } }, mounted() { use(this.fullName); } };
|
|
1802
|
+
</script>
|
|
1803
|
+
````
|
|
1804
|
+
|
|
1805
|
+
### `vue/no-use-v-if-with-v-for`
|
|
1806
|
+
|
|
1807
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow using `v-if` on the same element as `v-for`
|
|
1808
|
+
|
|
1809
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1810
|
+
- 自动修复:不支持或上游未声明
|
|
1811
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-use-v-if-with-v-for.html)
|
|
1812
|
+
- 常见报告:`This 'v-if' should be moved to the wrapper element.`;`The '{{iteratorName}}' {{kind}} inside 'v-for' directive should be replaced with a computed property that returns filtered array instead. You should not mix 'v-for' with 'v-if'.`
|
|
1813
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1814
|
+
|
|
1815
|
+
错误示例:
|
|
1816
|
+
|
|
1817
|
+
<!-- prettier-ignore -->
|
|
1818
|
+
````vue
|
|
1819
|
+
<template>
|
|
1820
|
+
<li v-for="item in items" v-if="item.visible">{{ item.name }}</li>
|
|
1821
|
+
</template>
|
|
1822
|
+
````
|
|
1823
|
+
|
|
1824
|
+
正确示例:
|
|
1825
|
+
|
|
1826
|
+
<!-- prettier-ignore -->
|
|
1827
|
+
````vue
|
|
1828
|
+
<template>
|
|
1829
|
+
<li v-for="item in visibleItems">{{ item.name }}</li>
|
|
1830
|
+
</template>
|
|
1831
|
+
````
|
|
1832
|
+
|
|
1833
|
+
### `vue/no-useless-template-attributes`
|
|
1834
|
+
|
|
1835
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow useless attribute on `<template>`
|
|
1836
|
+
|
|
1837
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1838
|
+
- 自动修复:不支持或上游未声明
|
|
1839
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-useless-template-attributes.html)
|
|
1840
|
+
- 常见报告:`Unexpected useless attribute on '<template>'.`;`Unexpected useless directive on '<template>'.`
|
|
1841
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1842
|
+
|
|
1843
|
+
错误示例:
|
|
1844
|
+
|
|
1845
|
+
<!-- prettier-ignore -->
|
|
1846
|
+
````vue
|
|
1847
|
+
<template>
|
|
1848
|
+
<template v-if="ready" class="wrapper"><p>Text</p></template>
|
|
1849
|
+
</template>
|
|
1850
|
+
````
|
|
1851
|
+
|
|
1852
|
+
正确示例:
|
|
1853
|
+
|
|
1854
|
+
<!-- prettier-ignore -->
|
|
1855
|
+
````vue
|
|
1856
|
+
<template>
|
|
1857
|
+
<template v-if="ready"><p class="wrapper">Text</p></template>
|
|
1858
|
+
</template>
|
|
1859
|
+
````
|
|
1860
|
+
|
|
1861
|
+
### `vue/no-v-for-template-key-on-child`
|
|
1862
|
+
|
|
1863
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow key of `<template v-for>` placed on child elements
|
|
1864
|
+
|
|
1865
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1866
|
+
- 自动修复:不支持或上游未声明
|
|
1867
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-v-for-template-key-on-child.html)
|
|
1868
|
+
- 常见报告:`'<template v-for>' key should be placed on the '<template>' tag.`
|
|
1869
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1870
|
+
|
|
1871
|
+
错误示例:
|
|
1872
|
+
|
|
1873
|
+
<!-- prettier-ignore -->
|
|
1874
|
+
````vue
|
|
1875
|
+
<template>
|
|
1876
|
+
<template v-for="item in items"><UserRow :key="item.id" /></template>
|
|
1877
|
+
</template>
|
|
1878
|
+
````
|
|
1879
|
+
|
|
1880
|
+
正确示例:
|
|
1881
|
+
|
|
1882
|
+
<!-- prettier-ignore -->
|
|
1883
|
+
````vue
|
|
1884
|
+
<template>
|
|
1885
|
+
<template v-for="item in items" :key="item.id"><UserRow /></template>
|
|
1886
|
+
</template>
|
|
1887
|
+
````
|
|
1888
|
+
|
|
1889
|
+
### `vue/no-watch-after-await`
|
|
1890
|
+
|
|
1891
|
+
禁止出现该规则定义的不安全、无效或易误解结构。上游说明:disallow asynchronously registered `watch`
|
|
1892
|
+
|
|
1893
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1894
|
+
- 自动修复:不支持或上游未声明
|
|
1895
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/no-watch-after-await.html)
|
|
1896
|
+
- 常见报告:`'watch' is forbidden after an 'await' expression.`
|
|
1897
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1898
|
+
|
|
1899
|
+
错误示例:
|
|
1900
|
+
|
|
1901
|
+
<!-- prettier-ignore -->
|
|
1902
|
+
````vue
|
|
1903
|
+
<script>import { watch } from 'vue';
|
|
1904
|
+
export default { async setup() { await load(); watch(source, update); } };</script>
|
|
1905
|
+
````
|
|
1906
|
+
|
|
1907
|
+
正确示例:
|
|
1908
|
+
|
|
1909
|
+
<!-- prettier-ignore -->
|
|
1910
|
+
````vue
|
|
1911
|
+
<script>import { watch } from 'vue';
|
|
1912
|
+
export default { async setup() { watch(source, update); await load(); } };</script>
|
|
1913
|
+
````
|
|
1914
|
+
|
|
1915
|
+
### `vue/order-in-components`
|
|
1916
|
+
|
|
1917
|
+
检查该规则对应的代码约束。上游说明:enforce order of properties in components
|
|
1918
|
+
|
|
1919
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
1920
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
1921
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/order-in-components.html)
|
|
1922
|
+
- 常见报告:`The "{{name}}" property should be above the "{{firstUnorderedPropertyName}}" property on line {{line}}.`;`Manually move "{{name}}" property above "{{firstUnorderedPropertyName}}" property on line {{line}} (might break side effects).`
|
|
1923
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1924
|
+
|
|
1925
|
+
错误示例:
|
|
1926
|
+
|
|
1927
|
+
<!-- prettier-ignore -->
|
|
1928
|
+
````vue
|
|
1929
|
+
<script>
|
|
1930
|
+
export default { methods: { save() {} }, props: { name: String }, data: () => ({ ready: false }) };
|
|
1931
|
+
</script>
|
|
1932
|
+
````
|
|
1933
|
+
|
|
1934
|
+
正确示例:
|
|
1935
|
+
|
|
1936
|
+
<!-- prettier-ignore -->
|
|
1937
|
+
````vue
|
|
1938
|
+
<script>
|
|
1939
|
+
export default { props: { name: String }, data: () => ({ ready: false }), methods: { save() {} } };
|
|
1940
|
+
</script>
|
|
1941
|
+
````
|
|
1942
|
+
|
|
1943
|
+
### `vue/prop-name-casing`
|
|
1944
|
+
|
|
1945
|
+
检查该规则对应的代码约束。上游说明:enforce specific casing for the Prop name in Vue components
|
|
1946
|
+
|
|
1947
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
1948
|
+
- 自动修复:不支持或上游未声明
|
|
1949
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/prop-name-casing.html)
|
|
1950
|
+
- 常见报告:`Prop "{{name}}" is not in {{caseType}}.`
|
|
1951
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1952
|
+
|
|
1953
|
+
错误示例:
|
|
1954
|
+
|
|
1955
|
+
<!-- prettier-ignore -->
|
|
1956
|
+
````vue
|
|
1957
|
+
<script>
|
|
1958
|
+
export default { props: { user_name: String } };
|
|
1959
|
+
</script>
|
|
1960
|
+
````
|
|
1961
|
+
|
|
1962
|
+
正确示例:
|
|
1963
|
+
|
|
1964
|
+
<!-- prettier-ignore -->
|
|
1965
|
+
````vue
|
|
1966
|
+
<script>
|
|
1967
|
+
export default { props: { userName: String } };
|
|
1968
|
+
</script>
|
|
1969
|
+
````
|
|
1970
|
+
|
|
1971
|
+
### `vue/require-component-is`
|
|
1972
|
+
|
|
1973
|
+
要求补齐该规则所需的声明、属性或结构。上游说明:require `v-bind:is` of `<component>` elements
|
|
1974
|
+
|
|
1975
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
1976
|
+
- 自动修复:不支持或上游未声明
|
|
1977
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/require-component-is.html)
|
|
1978
|
+
- 常见报告:`Expected '<component>' elements to have 'v-bind:is' attribute.`
|
|
1979
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
1980
|
+
|
|
1981
|
+
错误示例:
|
|
1982
|
+
|
|
1983
|
+
<!-- prettier-ignore -->
|
|
1984
|
+
````vue
|
|
1985
|
+
<template>
|
|
1986
|
+
<component />
|
|
1987
|
+
</template>
|
|
1988
|
+
````
|
|
1989
|
+
|
|
1990
|
+
正确示例:
|
|
1991
|
+
|
|
1992
|
+
<!-- prettier-ignore -->
|
|
1993
|
+
````vue
|
|
1994
|
+
<template>
|
|
1995
|
+
<component :is="currentComponent" />
|
|
1996
|
+
</template>
|
|
1997
|
+
````
|
|
1998
|
+
|
|
1999
|
+
### `vue/require-prop-type-constructor`
|
|
2000
|
+
|
|
2001
|
+
要求补齐该规则所需的声明、属性或结构。上游说明:require prop type to be a constructor
|
|
2002
|
+
|
|
2003
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2004
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
2005
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/require-prop-type-constructor.html)
|
|
2006
|
+
- 常见报告:`The "{{name}}" property should be a constructor.`
|
|
2007
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2008
|
+
|
|
2009
|
+
错误示例:
|
|
2010
|
+
|
|
2011
|
+
<!-- prettier-ignore -->
|
|
2012
|
+
````vue
|
|
2013
|
+
<script>
|
|
2014
|
+
export default { props: { name: { type: 'string' } } };
|
|
2015
|
+
</script>
|
|
2016
|
+
````
|
|
2017
|
+
|
|
2018
|
+
正确示例:
|
|
2019
|
+
|
|
2020
|
+
<!-- prettier-ignore -->
|
|
2021
|
+
````vue
|
|
2022
|
+
<script>
|
|
2023
|
+
export default { props: { name: { type: String } } };
|
|
2024
|
+
</script>
|
|
2025
|
+
````
|
|
2026
|
+
|
|
2027
|
+
### `vue/require-prop-types`
|
|
2028
|
+
|
|
2029
|
+
要求补齐该规则所需的声明、属性或结构。上游说明:require type definitions in props
|
|
2030
|
+
|
|
2031
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
2032
|
+
- 自动修复:不支持或上游未声明
|
|
2033
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/require-prop-types.html)
|
|
2034
|
+
- 常见报告:`Prop "{{name}}" should define at least its type.`
|
|
2035
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2036
|
+
|
|
2037
|
+
错误示例:
|
|
2038
|
+
|
|
2039
|
+
<!-- prettier-ignore -->
|
|
2040
|
+
````vue
|
|
2041
|
+
<script>
|
|
2042
|
+
export default { props: ['name'] };
|
|
2043
|
+
</script>
|
|
2044
|
+
````
|
|
2045
|
+
|
|
2046
|
+
正确示例:
|
|
2047
|
+
|
|
2048
|
+
<!-- prettier-ignore -->
|
|
2049
|
+
````vue
|
|
2050
|
+
<script>
|
|
2051
|
+
export default { props: { name: String } };
|
|
2052
|
+
</script>
|
|
2053
|
+
````
|
|
2054
|
+
|
|
2055
|
+
### `vue/require-render-return`
|
|
2056
|
+
|
|
2057
|
+
要求补齐该规则所需的声明、属性或结构。上游说明:enforce render function to always return value
|
|
2058
|
+
|
|
2059
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2060
|
+
- 自动修复:不支持或上游未声明
|
|
2061
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/require-render-return.html)
|
|
2062
|
+
- 常见报告:`Expected to return a value in render function.`
|
|
2063
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2064
|
+
|
|
2065
|
+
错误示例:
|
|
2066
|
+
|
|
2067
|
+
<!-- prettier-ignore -->
|
|
2068
|
+
````vue
|
|
2069
|
+
<script>
|
|
2070
|
+
export default { render() { createVNode('div'); } };
|
|
2071
|
+
</script>
|
|
2072
|
+
````
|
|
2073
|
+
|
|
2074
|
+
正确示例:
|
|
2075
|
+
|
|
2076
|
+
<!-- prettier-ignore -->
|
|
2077
|
+
````vue
|
|
2078
|
+
<script>
|
|
2079
|
+
export default { render() { return createVNode('div'); } };
|
|
2080
|
+
</script>
|
|
2081
|
+
````
|
|
2082
|
+
|
|
2083
|
+
### `vue/require-slots-as-functions`
|
|
2084
|
+
|
|
2085
|
+
要求补齐该规则所需的声明、属性或结构。上游说明:enforce properties of `$slots` to be used as a function
|
|
2086
|
+
|
|
2087
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2088
|
+
- 自动修复:不支持或上游未声明
|
|
2089
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/require-slots-as-functions.html)
|
|
2090
|
+
- 常见报告:`Property in '$slots' should be used as function.`
|
|
2091
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2092
|
+
|
|
2093
|
+
错误示例:
|
|
2094
|
+
|
|
2095
|
+
<!-- prettier-ignore -->
|
|
2096
|
+
````vue
|
|
2097
|
+
<script>
|
|
2098
|
+
export default { mounted() { const content = [this.$slots.default]; use(content); } };
|
|
2099
|
+
</script>
|
|
2100
|
+
````
|
|
2101
|
+
|
|
2102
|
+
正确示例:
|
|
2103
|
+
|
|
2104
|
+
<!-- prettier-ignore -->
|
|
2105
|
+
````vue
|
|
2106
|
+
<script>
|
|
2107
|
+
export default { mounted() { const content = [this.$slots.default?.()]; use(content); } };
|
|
2108
|
+
</script>
|
|
2109
|
+
````
|
|
2110
|
+
|
|
2111
|
+
### `vue/require-toggle-inside-transition`
|
|
2112
|
+
|
|
2113
|
+
要求补齐该规则所需的声明、属性或结构。上游说明:require control the display of the content inside `<transition>`
|
|
2114
|
+
|
|
2115
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2116
|
+
- 自动修复:不支持或上游未声明
|
|
2117
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/require-toggle-inside-transition.html)
|
|
2118
|
+
- 常见报告:`The element inside '<transition>' is expected to have a {{allowedDirectives}} directive.`
|
|
2119
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2120
|
+
|
|
2121
|
+
错误示例:
|
|
2122
|
+
|
|
2123
|
+
<!-- prettier-ignore -->
|
|
2124
|
+
````vue
|
|
2125
|
+
<template>
|
|
2126
|
+
<Transition><div>Always visible</div></Transition>
|
|
2127
|
+
</template>
|
|
2128
|
+
````
|
|
2129
|
+
|
|
2130
|
+
正确示例:
|
|
2131
|
+
|
|
2132
|
+
<!-- prettier-ignore -->
|
|
2133
|
+
````vue
|
|
2134
|
+
<template>
|
|
2135
|
+
<Transition><div v-if="visible">Visible</div></Transition>
|
|
2136
|
+
</template>
|
|
2137
|
+
````
|
|
2138
|
+
|
|
2139
|
+
### `vue/require-v-for-key`
|
|
2140
|
+
|
|
2141
|
+
要求补齐该规则所需的声明、属性或结构。上游说明:require `v-bind:key` with `v-for` directives
|
|
2142
|
+
|
|
2143
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2144
|
+
- 自动修复:不支持或上游未声明
|
|
2145
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/require-v-for-key.html)
|
|
2146
|
+
- 常见报告:`Elements in iteration expect to have 'v-bind:key' directives.`
|
|
2147
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2148
|
+
|
|
2149
|
+
错误示例:
|
|
2150
|
+
|
|
2151
|
+
<!-- prettier-ignore -->
|
|
2152
|
+
````vue
|
|
2153
|
+
<template>
|
|
2154
|
+
<div v-for="item in items">{{ item.name }}</div>
|
|
2155
|
+
</template>
|
|
2156
|
+
````
|
|
2157
|
+
|
|
2158
|
+
正确示例:
|
|
2159
|
+
|
|
2160
|
+
<!-- prettier-ignore -->
|
|
2161
|
+
````vue
|
|
2162
|
+
<template>
|
|
2163
|
+
<div v-for="item in items" :key="item.id">{{ item.name }}</div>
|
|
2164
|
+
</template>
|
|
2165
|
+
````
|
|
2166
|
+
|
|
2167
|
+
### `vue/require-valid-default-prop`
|
|
2168
|
+
|
|
2169
|
+
要求补齐该规则所需的声明、属性或结构。上游说明:enforce props default values to be valid
|
|
2170
|
+
|
|
2171
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2172
|
+
- 自动修复:不支持或上游未声明
|
|
2173
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/require-valid-default-prop.html)
|
|
2174
|
+
- 常见报告:`Type of the default value for '{{name}}' prop must be a {{types}}.`
|
|
2175
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2176
|
+
|
|
2177
|
+
错误示例:
|
|
2178
|
+
|
|
2179
|
+
<!-- prettier-ignore -->
|
|
2180
|
+
````vue
|
|
2181
|
+
<script>
|
|
2182
|
+
export default { props: { items: { type: Array, default: [] } } };
|
|
2183
|
+
</script>
|
|
2184
|
+
````
|
|
2185
|
+
|
|
2186
|
+
正确示例:
|
|
2187
|
+
|
|
2188
|
+
<!-- prettier-ignore -->
|
|
2189
|
+
````vue
|
|
2190
|
+
<script>
|
|
2191
|
+
export default { props: { items: { type: Array, default: () => [] } } };
|
|
2192
|
+
</script>
|
|
2193
|
+
````
|
|
2194
|
+
|
|
2195
|
+
### `vue/return-in-computed-property`
|
|
2196
|
+
|
|
2197
|
+
检查该规则对应的代码约束。上游说明:enforce that a return statement is present in computed property
|
|
2198
|
+
|
|
2199
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2200
|
+
- 自动修复:不支持或上游未声明
|
|
2201
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/return-in-computed-property.html)
|
|
2202
|
+
- 常见报告:`Expected to return a value in computed function.`;`Expected to return a value in "{{name}}" computed property.`
|
|
2203
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2204
|
+
|
|
2205
|
+
错误示例:
|
|
2206
|
+
|
|
2207
|
+
<!-- prettier-ignore -->
|
|
2208
|
+
````vue
|
|
2209
|
+
<script>
|
|
2210
|
+
export default { computed: { label() { if (this.name) return this.name; } } };
|
|
2211
|
+
</script>
|
|
2212
|
+
````
|
|
2213
|
+
|
|
2214
|
+
正确示例:
|
|
2215
|
+
|
|
2216
|
+
<!-- prettier-ignore -->
|
|
2217
|
+
````vue
|
|
2218
|
+
<script>
|
|
2219
|
+
export default { computed: { label() { return this.name || 'Anonymous'; } } };
|
|
2220
|
+
</script>
|
|
2221
|
+
````
|
|
2222
|
+
|
|
2223
|
+
### `vue/return-in-emits-validator`
|
|
2224
|
+
|
|
2225
|
+
检查该规则对应的代码约束。上游说明:enforce that a return statement is present in emits validator
|
|
2226
|
+
|
|
2227
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2228
|
+
- 自动修复:不支持或上游未声明
|
|
2229
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/return-in-emits-validator.html)
|
|
2230
|
+
- 常见报告:`Expected to return a true value in "{{name}}" emits validator.`;`Expected to return a boolean value in "{{name}}" emits validator.`
|
|
2231
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2232
|
+
|
|
2233
|
+
错误示例:
|
|
2234
|
+
|
|
2235
|
+
<!-- prettier-ignore -->
|
|
2236
|
+
````vue
|
|
2237
|
+
<script setup>const emit = defineEmits({ save(payload) { validate(payload); } });</script>
|
|
2238
|
+
````
|
|
2239
|
+
|
|
2240
|
+
正确示例:
|
|
2241
|
+
|
|
2242
|
+
<!-- prettier-ignore -->
|
|
2243
|
+
````vue
|
|
2244
|
+
<script setup>const emit = defineEmits({ save(payload) { return validate(payload); } });</script>
|
|
2245
|
+
````
|
|
2246
|
+
|
|
2247
|
+
### `vue/this-in-template`
|
|
2248
|
+
|
|
2249
|
+
检查该规则对应的代码约束。上游说明:disallow usage of `this` in template
|
|
2250
|
+
|
|
2251
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
2252
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
2253
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/this-in-template.html)
|
|
2254
|
+
- 常见报告:`Unexpected usage of 'this'.`;`Expected 'this'.`
|
|
2255
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2256
|
+
|
|
2257
|
+
错误示例:
|
|
2258
|
+
|
|
2259
|
+
<!-- prettier-ignore -->
|
|
2260
|
+
````vue
|
|
2261
|
+
<template>
|
|
2262
|
+
<p>{{ this.name }}</p>
|
|
2263
|
+
</template>
|
|
2264
|
+
````
|
|
2265
|
+
|
|
2266
|
+
正确示例:
|
|
2267
|
+
|
|
2268
|
+
<!-- prettier-ignore -->
|
|
2269
|
+
````vue
|
|
2270
|
+
<template>
|
|
2271
|
+
<p>{{ name }}</p>
|
|
2272
|
+
</template>
|
|
2273
|
+
````
|
|
2274
|
+
|
|
2275
|
+
### `vue/use-v-on-exact`
|
|
2276
|
+
|
|
2277
|
+
检查该规则对应的代码约束。上游说明:enforce usage of `exact` modifier on `v-on`
|
|
2278
|
+
|
|
2279
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2280
|
+
- 自动修复:不支持或上游未声明
|
|
2281
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/use-v-on-exact.html)
|
|
2282
|
+
- 常见报告:`Consider to use '.exact' modifier.`
|
|
2283
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2284
|
+
|
|
2285
|
+
错误示例:
|
|
2286
|
+
|
|
2287
|
+
<!-- prettier-ignore -->
|
|
2288
|
+
````vue
|
|
2289
|
+
<template>
|
|
2290
|
+
<button @click="select" @click.ctrl="selectMultiple">Select</button>
|
|
2291
|
+
</template>
|
|
2292
|
+
````
|
|
2293
|
+
|
|
2294
|
+
正确示例:
|
|
2295
|
+
|
|
2296
|
+
<!-- prettier-ignore -->
|
|
2297
|
+
````vue
|
|
2298
|
+
<template>
|
|
2299
|
+
<button @click.exact="select" @click.ctrl.exact="selectMultiple">Select</button>
|
|
2300
|
+
</template>
|
|
2301
|
+
````
|
|
2302
|
+
|
|
2303
|
+
### `vue/v-bind-style`
|
|
2304
|
+
|
|
2305
|
+
检查该规则对应的代码约束。上游说明:enforce `v-bind` directive style
|
|
2306
|
+
|
|
2307
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
2308
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
2309
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/v-bind-style.html)
|
|
2310
|
+
- 常见报告:`Expected 'v-bind' before ':'.`;`Unexpected 'v-bind' before ':'.`;`Expected 'v-bind:' instead of '.'.`
|
|
2311
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2312
|
+
|
|
2313
|
+
错误示例:
|
|
2314
|
+
|
|
2315
|
+
<!-- prettier-ignore -->
|
|
2316
|
+
````vue
|
|
2317
|
+
<template>
|
|
2318
|
+
<UserCard v-bind:name="name" />
|
|
2319
|
+
</template>
|
|
2320
|
+
````
|
|
2321
|
+
|
|
2322
|
+
正确示例:
|
|
2323
|
+
|
|
2324
|
+
<!-- prettier-ignore -->
|
|
2325
|
+
````vue
|
|
2326
|
+
<template>
|
|
2327
|
+
<UserCard :name="name" />
|
|
2328
|
+
</template>
|
|
2329
|
+
````
|
|
2330
|
+
|
|
2331
|
+
### `vue/v-on-event-hyphenation`
|
|
2332
|
+
|
|
2333
|
+
检查该规则对应的代码约束。上游说明:enforce v-on event naming style on custom components in template
|
|
2334
|
+
|
|
2335
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
2336
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
2337
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/v-on-event-hyphenation.html)
|
|
2338
|
+
- 常见报告:`v-on event '{{text}}' must be hyphenated.`;`v-on event '{{text}}' can't be hyphenated.`
|
|
2339
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2340
|
+
|
|
2341
|
+
错误示例:
|
|
2342
|
+
|
|
2343
|
+
<!-- prettier-ignore -->
|
|
2344
|
+
````vue
|
|
2345
|
+
<template>
|
|
2346
|
+
<UserCard @saveItem="save" />
|
|
2347
|
+
</template>
|
|
2348
|
+
````
|
|
2349
|
+
|
|
2350
|
+
正确示例:
|
|
2351
|
+
|
|
2352
|
+
<!-- prettier-ignore -->
|
|
2353
|
+
````vue
|
|
2354
|
+
<template>
|
|
2355
|
+
<UserCard @save-item="save" />
|
|
2356
|
+
</template>
|
|
2357
|
+
````
|
|
2358
|
+
|
|
2359
|
+
### `vue/v-on-style`
|
|
2360
|
+
|
|
2361
|
+
检查该规则对应的代码约束。上游说明:enforce `v-on` directive style
|
|
2362
|
+
|
|
2363
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
2364
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
2365
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/v-on-style.html)
|
|
2366
|
+
- 常见报告:`Expected '@' instead of 'v-on:'.`;`Expected 'v-on:' instead of '@'.`
|
|
2367
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2368
|
+
|
|
2369
|
+
错误示例:
|
|
2370
|
+
|
|
2371
|
+
<!-- prettier-ignore -->
|
|
2372
|
+
````vue
|
|
2373
|
+
<template>
|
|
2374
|
+
<button v-on:click="save">Save</button>
|
|
2375
|
+
</template>
|
|
2376
|
+
````
|
|
2377
|
+
|
|
2378
|
+
正确示例:
|
|
2379
|
+
|
|
2380
|
+
<!-- prettier-ignore -->
|
|
2381
|
+
````vue
|
|
2382
|
+
<template>
|
|
2383
|
+
<button @click="save">Save</button>
|
|
2384
|
+
</template>
|
|
2385
|
+
````
|
|
2386
|
+
|
|
2387
|
+
### `vue/v-slot-style`
|
|
2388
|
+
|
|
2389
|
+
检查该规则对应的代码约束。上游说明:enforce `v-slot` directive style
|
|
2390
|
+
|
|
2391
|
+
- 生效级别与范围:warn: Vue SFC、UniApp NVue
|
|
2392
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
2393
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/v-slot-style.html)
|
|
2394
|
+
- 常见报告:`Expected '#{{argument}}' instead of '{{actual}}'.`;`Expected 'v-slot:{{argument}}' instead of '{{actual}}'.`;`Expected 'v-slot' instead of '{{actual}}'.`
|
|
2395
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2396
|
+
|
|
2397
|
+
错误示例:
|
|
2398
|
+
|
|
2399
|
+
<!-- prettier-ignore -->
|
|
2400
|
+
````vue
|
|
2401
|
+
<template>
|
|
2402
|
+
<template v-slot:header>Title</template>
|
|
2403
|
+
</template>
|
|
2404
|
+
````
|
|
2405
|
+
|
|
2406
|
+
正确示例:
|
|
2407
|
+
|
|
2408
|
+
<!-- prettier-ignore -->
|
|
2409
|
+
````vue
|
|
2410
|
+
<template>
|
|
2411
|
+
<template #header>Title</template>
|
|
2412
|
+
</template>
|
|
2413
|
+
````
|
|
2414
|
+
|
|
2415
|
+
### `vue/valid-attribute-name`
|
|
2416
|
+
|
|
2417
|
+
校验对应语法、属性或参数是否合法。上游说明:require valid attribute names
|
|
2418
|
+
|
|
2419
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2420
|
+
- 自动修复:不支持或上游未声明
|
|
2421
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-attribute-name.html)
|
|
2422
|
+
- 常见报告:`Attribute name {{name}} is not valid.`
|
|
2423
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2424
|
+
|
|
2425
|
+
错误示例:
|
|
2426
|
+
|
|
2427
|
+
<!-- prettier-ignore -->
|
|
2428
|
+
````vue
|
|
2429
|
+
<template>
|
|
2430
|
+
<div bad"name="value" />
|
|
2431
|
+
</template>
|
|
2432
|
+
````
|
|
2433
|
+
|
|
2434
|
+
正确示例:
|
|
2435
|
+
|
|
2436
|
+
<!-- prettier-ignore -->
|
|
2437
|
+
````vue
|
|
2438
|
+
<template>
|
|
2439
|
+
<div data-name="value" />
|
|
2440
|
+
</template>
|
|
2441
|
+
````
|
|
2442
|
+
|
|
2443
|
+
### `vue/valid-define-emits`
|
|
2444
|
+
|
|
2445
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `defineEmits` compiler macro
|
|
2446
|
+
|
|
2447
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2448
|
+
- 自动修复:不支持或上游未声明
|
|
2449
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-define-emits.html)
|
|
2450
|
+
- 常见报告:`'defineEmits' has both a type-only emit and an argument.`;`'defineEmits' is referencing locally declared variables.`;`'defineEmits' has been called multiple times.`
|
|
2451
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2452
|
+
|
|
2453
|
+
错误示例:
|
|
2454
|
+
|
|
2455
|
+
<!-- prettier-ignore -->
|
|
2456
|
+
````vue
|
|
2457
|
+
<script setup>defineEmits(['save']);
|
|
2458
|
+
defineEmits(['cancel']);</script>
|
|
2459
|
+
````
|
|
2460
|
+
|
|
2461
|
+
正确示例:
|
|
2462
|
+
|
|
2463
|
+
<!-- prettier-ignore -->
|
|
2464
|
+
````vue
|
|
2465
|
+
<script setup>const emit = defineEmits(['save', 'cancel']);</script>
|
|
2466
|
+
````
|
|
2467
|
+
|
|
2468
|
+
### `vue/valid-define-options`
|
|
2469
|
+
|
|
2470
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `defineOptions` compiler macro
|
|
2471
|
+
|
|
2472
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2473
|
+
- 自动修复:不支持或上游未声明
|
|
2474
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-define-options.html)
|
|
2475
|
+
- 常见报告:`'defineOptions' is referencing locally declared variables.`;`'defineOptions' has been called multiple times.`;`Options are not defined.`
|
|
2476
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2477
|
+
|
|
2478
|
+
错误示例:
|
|
2479
|
+
|
|
2480
|
+
<!-- prettier-ignore -->
|
|
2481
|
+
````vue
|
|
2482
|
+
<script setup>const componentName = getComponentName();
|
|
2483
|
+
defineOptions({ name: componentName });</script>
|
|
2484
|
+
````
|
|
2485
|
+
|
|
2486
|
+
正确示例:
|
|
2487
|
+
|
|
2488
|
+
<!-- prettier-ignore -->
|
|
2489
|
+
````vue
|
|
2490
|
+
<script setup>defineOptions({ name: 'UserCard' });</script>
|
|
2491
|
+
````
|
|
2492
|
+
|
|
2493
|
+
### `vue/valid-define-props`
|
|
2494
|
+
|
|
2495
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `defineProps` compiler macro
|
|
2496
|
+
|
|
2497
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2498
|
+
- 自动修复:不支持或上游未声明
|
|
2499
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-define-props.html)
|
|
2500
|
+
- 常见报告:`'defineProps' has both a type-only props and an argument.`;`'defineProps' is referencing locally declared variables.`;`'defineProps' has been called multiple times.`
|
|
2501
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2502
|
+
|
|
2503
|
+
错误示例:
|
|
2504
|
+
|
|
2505
|
+
<!-- prettier-ignore -->
|
|
2506
|
+
````vue
|
|
2507
|
+
<script setup>defineProps(['name']);
|
|
2508
|
+
defineProps(['age']);</script>
|
|
2509
|
+
````
|
|
2510
|
+
|
|
2511
|
+
正确示例:
|
|
2512
|
+
|
|
2513
|
+
<!-- prettier-ignore -->
|
|
2514
|
+
````vue
|
|
2515
|
+
<script setup>const props = defineProps(['name', 'age']);</script>
|
|
2516
|
+
````
|
|
2517
|
+
|
|
2518
|
+
### `vue/valid-next-tick`
|
|
2519
|
+
|
|
2520
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `nextTick` function calls
|
|
2521
|
+
|
|
2522
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2523
|
+
- 自动修复:支持;执行前仍应检查语义和差异
|
|
2524
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-next-tick.html)
|
|
2525
|
+
- 常见报告:`'nextTick' is a function.`;`Await the Promise returned by 'nextTick' or pass a callback function.`;`Add missing 'await' statement.`
|
|
2526
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2527
|
+
|
|
2528
|
+
错误示例:
|
|
2529
|
+
|
|
2530
|
+
<!-- prettier-ignore -->
|
|
2531
|
+
````vue
|
|
2532
|
+
<script>
|
|
2533
|
+
export default { mounted() { this.$nextTick(); } };
|
|
2534
|
+
</script>
|
|
2535
|
+
````
|
|
2536
|
+
|
|
2537
|
+
正确示例:
|
|
2538
|
+
|
|
2539
|
+
<!-- prettier-ignore -->
|
|
2540
|
+
````vue
|
|
2541
|
+
<script>
|
|
2542
|
+
export default { mounted() { this.$nextTick(() => updateLayout()); } };
|
|
2543
|
+
</script>
|
|
2544
|
+
````
|
|
2545
|
+
|
|
2546
|
+
### `vue/valid-template-root`
|
|
2547
|
+
|
|
2548
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid template root
|
|
2549
|
+
|
|
2550
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2551
|
+
- 自动修复:不支持或上游未声明
|
|
2552
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-template-root.html)
|
|
2553
|
+
- 常见报告:`The template root with 'src' attribute is required to be empty.`;`The template requires child element.`
|
|
2554
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2555
|
+
|
|
2556
|
+
错误示例:
|
|
2557
|
+
|
|
2558
|
+
<!-- prettier-ignore -->
|
|
2559
|
+
````vue
|
|
2560
|
+
<template></template>
|
|
2561
|
+
````
|
|
2562
|
+
|
|
2563
|
+
正确示例:
|
|
2564
|
+
|
|
2565
|
+
<!-- prettier-ignore -->
|
|
2566
|
+
````vue
|
|
2567
|
+
<template><main>Content</main></template>
|
|
2568
|
+
````
|
|
2569
|
+
|
|
2570
|
+
### `vue/valid-v-bind`
|
|
2571
|
+
|
|
2572
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-bind` directives
|
|
2573
|
+
|
|
2574
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2575
|
+
- 自动修复:不支持或上游未声明
|
|
2576
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-bind.html)
|
|
2577
|
+
- 常见报告:`'v-bind' directives don't support the modifier '{{name}}'.`;`'v-bind' directives require an attribute value.`
|
|
2578
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2579
|
+
|
|
2580
|
+
错误示例:
|
|
2581
|
+
|
|
2582
|
+
<!-- prettier-ignore -->
|
|
2583
|
+
````vue
|
|
2584
|
+
<template>
|
|
2585
|
+
<div v-bind:class />
|
|
2586
|
+
</template>
|
|
2587
|
+
````
|
|
2588
|
+
|
|
2589
|
+
正确示例:
|
|
2590
|
+
|
|
2591
|
+
<!-- prettier-ignore -->
|
|
2592
|
+
````vue
|
|
2593
|
+
<template>
|
|
2594
|
+
<div :class="classes" />
|
|
2595
|
+
</template>
|
|
2596
|
+
````
|
|
2597
|
+
|
|
2598
|
+
### `vue/valid-v-cloak`
|
|
2599
|
+
|
|
2600
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-cloak` directives
|
|
2601
|
+
|
|
2602
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2603
|
+
- 自动修复:不支持或上游未声明
|
|
2604
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-cloak.html)
|
|
2605
|
+
- 常见报告:`'v-cloak' directives require no argument.`;`'v-cloak' directives require no modifier.`;`'v-cloak' directives require no attribute value.`
|
|
2606
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2607
|
+
|
|
2608
|
+
错误示例:
|
|
2609
|
+
|
|
2610
|
+
<!-- prettier-ignore -->
|
|
2611
|
+
````vue
|
|
2612
|
+
<template>
|
|
2613
|
+
<div v-cloak="ready" />
|
|
2614
|
+
</template>
|
|
2615
|
+
````
|
|
2616
|
+
|
|
2617
|
+
正确示例:
|
|
2618
|
+
|
|
2619
|
+
<!-- prettier-ignore -->
|
|
2620
|
+
````vue
|
|
2621
|
+
<template>
|
|
2622
|
+
<div v-cloak />
|
|
2623
|
+
</template>
|
|
2624
|
+
````
|
|
2625
|
+
|
|
2626
|
+
### `vue/valid-v-else`
|
|
2627
|
+
|
|
2628
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-else` directives
|
|
2629
|
+
|
|
2630
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2631
|
+
- 自动修复:不支持或上游未声明
|
|
2632
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-else.html)
|
|
2633
|
+
- 常见报告:`'v-else' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive.`;`'v-else' and 'v-if' directives can't exist on the same element. You may want 'v-else-if' directives.`;`'v-else' and 'v-else-if' directives can't exist on the same element.`
|
|
2634
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2635
|
+
|
|
2636
|
+
错误示例:
|
|
2637
|
+
|
|
2638
|
+
<!-- prettier-ignore -->
|
|
2639
|
+
````vue
|
|
2640
|
+
<template>
|
|
2641
|
+
<p v-else="ready">Fallback</p>
|
|
2642
|
+
</template>
|
|
2643
|
+
````
|
|
2644
|
+
|
|
2645
|
+
正确示例:
|
|
2646
|
+
|
|
2647
|
+
<!-- prettier-ignore -->
|
|
2648
|
+
````vue
|
|
2649
|
+
<template>
|
|
2650
|
+
<p v-if="ready">Ready</p><p v-else>Fallback</p>
|
|
2651
|
+
</template>
|
|
2652
|
+
````
|
|
2653
|
+
|
|
2654
|
+
### `vue/valid-v-else-if`
|
|
2655
|
+
|
|
2656
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-else-if` directives
|
|
2657
|
+
|
|
2658
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2659
|
+
- 自动修复:不支持或上游未声明
|
|
2660
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-else-if.html)
|
|
2661
|
+
- 常见报告:`'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive.`;`'v-else-if' and 'v-if' directives can't exist on the same element.`;`'v-else-if' and 'v-else' directives can't exist on the same element.`
|
|
2662
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2663
|
+
|
|
2664
|
+
错误示例:
|
|
2665
|
+
|
|
2666
|
+
<!-- prettier-ignore -->
|
|
2667
|
+
````vue
|
|
2668
|
+
<template>
|
|
2669
|
+
<p v-else-if>Loading</p>
|
|
2670
|
+
</template>
|
|
2671
|
+
````
|
|
2672
|
+
|
|
2673
|
+
正确示例:
|
|
2674
|
+
|
|
2675
|
+
<!-- prettier-ignore -->
|
|
2676
|
+
````vue
|
|
2677
|
+
<template>
|
|
2678
|
+
<p v-if="ready">Ready</p><p v-else-if="loading">Loading</p>
|
|
2679
|
+
</template>
|
|
2680
|
+
````
|
|
2681
|
+
|
|
2682
|
+
### `vue/valid-v-for`
|
|
2683
|
+
|
|
2684
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-for` directives
|
|
2685
|
+
|
|
2686
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2687
|
+
- 自动修复:不支持或上游未声明
|
|
2688
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-for.html)
|
|
2689
|
+
- 常见报告:`Custom elements in iteration require 'v-bind:key' directives.`;`Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive.`;`'v-for' directives require no argument.`
|
|
2690
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2691
|
+
|
|
2692
|
+
错误示例:
|
|
2693
|
+
|
|
2694
|
+
<!-- prettier-ignore -->
|
|
2695
|
+
````vue
|
|
2696
|
+
<template>
|
|
2697
|
+
<li v-for>Item</li>
|
|
2698
|
+
</template>
|
|
2699
|
+
````
|
|
2700
|
+
|
|
2701
|
+
正确示例:
|
|
2702
|
+
|
|
2703
|
+
<!-- prettier-ignore -->
|
|
2704
|
+
````vue
|
|
2705
|
+
<template>
|
|
2706
|
+
<li v-for="item in items" :key="item.id">{{ item.name }}</li>
|
|
2707
|
+
</template>
|
|
2708
|
+
````
|
|
2709
|
+
|
|
2710
|
+
### `vue/valid-v-html`
|
|
2711
|
+
|
|
2712
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-html` directives
|
|
2713
|
+
|
|
2714
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2715
|
+
- 自动修复:不支持或上游未声明
|
|
2716
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-html.html)
|
|
2717
|
+
- 常见报告:`'v-html' directives require no argument.`;`'v-html' directives require no modifier.`;`'v-html' directives require that attribute value.`
|
|
2718
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2719
|
+
|
|
2720
|
+
错误示例:
|
|
2721
|
+
|
|
2722
|
+
<!-- prettier-ignore -->
|
|
2723
|
+
````vue
|
|
2724
|
+
<template>
|
|
2725
|
+
<div v-html />
|
|
2726
|
+
</template>
|
|
2727
|
+
````
|
|
2728
|
+
|
|
2729
|
+
正确示例:
|
|
2730
|
+
|
|
2731
|
+
<!-- prettier-ignore -->
|
|
2732
|
+
````vue
|
|
2733
|
+
<template>
|
|
2734
|
+
<div v-html="sanitizedHtml" />
|
|
2735
|
+
</template>
|
|
2736
|
+
````
|
|
2737
|
+
|
|
2738
|
+
### `vue/valid-v-if`
|
|
2739
|
+
|
|
2740
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-if` directives
|
|
2741
|
+
|
|
2742
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2743
|
+
- 自动修复:不支持或上游未声明
|
|
2744
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-if.html)
|
|
2745
|
+
- 常见报告:`'v-if' and 'v-else' directives can't exist on the same element. You may want 'v-else-if' directives.`;`'v-if' and 'v-else-if' directives can't exist on the same element.`;`'v-if' directives require no argument.`
|
|
2746
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2747
|
+
|
|
2748
|
+
错误示例:
|
|
2749
|
+
|
|
2750
|
+
<!-- prettier-ignore -->
|
|
2751
|
+
````vue
|
|
2752
|
+
<template>
|
|
2753
|
+
<p v-if>Ready</p>
|
|
2754
|
+
</template>
|
|
2755
|
+
````
|
|
2756
|
+
|
|
2757
|
+
正确示例:
|
|
2758
|
+
|
|
2759
|
+
<!-- prettier-ignore -->
|
|
2760
|
+
````vue
|
|
2761
|
+
<template>
|
|
2762
|
+
<p v-if="ready">Ready</p>
|
|
2763
|
+
</template>
|
|
2764
|
+
````
|
|
2765
|
+
|
|
2766
|
+
### `vue/valid-v-is`
|
|
2767
|
+
|
|
2768
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-is` directives
|
|
2769
|
+
|
|
2770
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2771
|
+
- 自动修复:不支持或上游未声明
|
|
2772
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-is.html)
|
|
2773
|
+
- 常见报告:`'v-is' directives require no argument.`;`'v-is' directives require no modifier.`;`'v-is' directives require that attribute value.`
|
|
2774
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2775
|
+
|
|
2776
|
+
错误示例:
|
|
2777
|
+
|
|
2778
|
+
<!-- prettier-ignore -->
|
|
2779
|
+
````vue
|
|
2780
|
+
<template>
|
|
2781
|
+
<div v-is />
|
|
2782
|
+
</template>
|
|
2783
|
+
````
|
|
2784
|
+
|
|
2785
|
+
正确示例:
|
|
2786
|
+
|
|
2787
|
+
<!-- prettier-ignore -->
|
|
2788
|
+
````vue
|
|
2789
|
+
<template>
|
|
2790
|
+
<component :is="currentComponent" />
|
|
2791
|
+
</template>
|
|
2792
|
+
````
|
|
2793
|
+
|
|
2794
|
+
### `vue/valid-v-memo`
|
|
2795
|
+
|
|
2796
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-memo` directives
|
|
2797
|
+
|
|
2798
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2799
|
+
- 自动修复:不支持或上游未声明
|
|
2800
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-memo.html)
|
|
2801
|
+
- 常见报告:`'v-memo' directives require no argument.`;`'v-memo' directives require no modifier.`;`'v-memo' directives require that attribute value.`
|
|
2802
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2803
|
+
|
|
2804
|
+
错误示例:
|
|
2805
|
+
|
|
2806
|
+
<!-- prettier-ignore -->
|
|
2807
|
+
````vue
|
|
2808
|
+
<template>
|
|
2809
|
+
<div v-memo />
|
|
2810
|
+
</template>
|
|
2811
|
+
````
|
|
2812
|
+
|
|
2813
|
+
正确示例:
|
|
2814
|
+
|
|
2815
|
+
<!-- prettier-ignore -->
|
|
2816
|
+
````vue
|
|
2817
|
+
<template>
|
|
2818
|
+
<div v-memo="[count]" />
|
|
2819
|
+
</template>
|
|
2820
|
+
````
|
|
2821
|
+
|
|
2822
|
+
### `vue/valid-v-model`
|
|
2823
|
+
|
|
2824
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-model` directives
|
|
2825
|
+
|
|
2826
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2827
|
+
- 自动修复:不支持或上游未声明
|
|
2828
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-model.html)
|
|
2829
|
+
- 常见报告:`'v-model' directives aren't supported on <{{name}}> elements.`;`'v-model' directives don't support 'file' input type.`;`'v-model' directives require no argument.`
|
|
2830
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2831
|
+
|
|
2832
|
+
错误示例:
|
|
2833
|
+
|
|
2834
|
+
<!-- prettier-ignore -->
|
|
2835
|
+
````vue
|
|
2836
|
+
<template>
|
|
2837
|
+
<input v-model:color="color" />
|
|
2838
|
+
</template>
|
|
2839
|
+
````
|
|
2840
|
+
|
|
2841
|
+
正确示例:
|
|
2842
|
+
|
|
2843
|
+
<!-- prettier-ignore -->
|
|
2844
|
+
````vue
|
|
2845
|
+
<template>
|
|
2846
|
+
<input v-model="color" />
|
|
2847
|
+
</template>
|
|
2848
|
+
````
|
|
2849
|
+
|
|
2850
|
+
### `vue/valid-v-on`
|
|
2851
|
+
|
|
2852
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-on` directives
|
|
2853
|
+
|
|
2854
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2855
|
+
- 自动修复:不支持或上游未声明
|
|
2856
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-on.html)
|
|
2857
|
+
- 常见报告:`'v-on' directives don't support the modifier '{{modifier}}'.`;`Avoid using JavaScript keyword as "v-on" value: {{value}}.`;`'v-on' directives require a value or verb modifier (like 'stop' or 'prevent').`
|
|
2858
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2859
|
+
|
|
2860
|
+
错误示例:
|
|
2861
|
+
|
|
2862
|
+
<!-- prettier-ignore -->
|
|
2863
|
+
````vue
|
|
2864
|
+
<template>
|
|
2865
|
+
<button v-on>Save</button>
|
|
2866
|
+
</template>
|
|
2867
|
+
````
|
|
2868
|
+
|
|
2869
|
+
正确示例:
|
|
2870
|
+
|
|
2871
|
+
<!-- prettier-ignore -->
|
|
2872
|
+
````vue
|
|
2873
|
+
<template>
|
|
2874
|
+
<button @click="save">Save</button>
|
|
2875
|
+
</template>
|
|
2876
|
+
````
|
|
2877
|
+
|
|
2878
|
+
### `vue/valid-v-once`
|
|
2879
|
+
|
|
2880
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-once` directives
|
|
2881
|
+
|
|
2882
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2883
|
+
- 自动修复:不支持或上游未声明
|
|
2884
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-once.html)
|
|
2885
|
+
- 常见报告:`'v-once' directives require no argument.`;`'v-once' directives require no modifier.`;`'v-once' directives require no attribute value.`
|
|
2886
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2887
|
+
|
|
2888
|
+
错误示例:
|
|
2889
|
+
|
|
2890
|
+
<!-- prettier-ignore -->
|
|
2891
|
+
````vue
|
|
2892
|
+
<template>
|
|
2893
|
+
<p v-once:label>Static</p>
|
|
2894
|
+
</template>
|
|
2895
|
+
````
|
|
2896
|
+
|
|
2897
|
+
正确示例:
|
|
2898
|
+
|
|
2899
|
+
<!-- prettier-ignore -->
|
|
2900
|
+
````vue
|
|
2901
|
+
<template>
|
|
2902
|
+
<p v-once>Static</p>
|
|
2903
|
+
</template>
|
|
2904
|
+
````
|
|
2905
|
+
|
|
2906
|
+
### `vue/valid-v-pre`
|
|
2907
|
+
|
|
2908
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-pre` directives
|
|
2909
|
+
|
|
2910
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2911
|
+
- 自动修复:不支持或上游未声明
|
|
2912
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-pre.html)
|
|
2913
|
+
- 常见报告:`'v-pre' directives require no argument.`;`'v-pre' directives require no modifier.`;`'v-pre' directives require no attribute value.`
|
|
2914
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2915
|
+
|
|
2916
|
+
错误示例:
|
|
2917
|
+
|
|
2918
|
+
<!-- prettier-ignore -->
|
|
2919
|
+
````vue
|
|
2920
|
+
<template>
|
|
2921
|
+
<p v-pre="enabled">{{ raw }}</p>
|
|
2922
|
+
</template>
|
|
2923
|
+
````
|
|
2924
|
+
|
|
2925
|
+
正确示例:
|
|
2926
|
+
|
|
2927
|
+
<!-- prettier-ignore -->
|
|
2928
|
+
````vue
|
|
2929
|
+
<template>
|
|
2930
|
+
<p v-pre>{{ raw }}</p>
|
|
2931
|
+
</template>
|
|
2932
|
+
````
|
|
2933
|
+
|
|
2934
|
+
### `vue/valid-v-show`
|
|
2935
|
+
|
|
2936
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-show` directives
|
|
2937
|
+
|
|
2938
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2939
|
+
- 自动修复:不支持或上游未声明
|
|
2940
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-show.html)
|
|
2941
|
+
- 常见报告:`'v-show' directives require no argument.`;`'v-show' directives require no modifier.`;`'v-show' directives require that attribute value.`
|
|
2942
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2943
|
+
|
|
2944
|
+
错误示例:
|
|
2945
|
+
|
|
2946
|
+
<!-- prettier-ignore -->
|
|
2947
|
+
````vue
|
|
2948
|
+
<template>
|
|
2949
|
+
<p v-show>Visible</p>
|
|
2950
|
+
</template>
|
|
2951
|
+
````
|
|
2952
|
+
|
|
2953
|
+
正确示例:
|
|
2954
|
+
|
|
2955
|
+
<!-- prettier-ignore -->
|
|
2956
|
+
````vue
|
|
2957
|
+
<template>
|
|
2958
|
+
<p v-show="visible">Visible</p>
|
|
2959
|
+
</template>
|
|
2960
|
+
````
|
|
2961
|
+
|
|
2962
|
+
### `vue/valid-v-slot`
|
|
2963
|
+
|
|
2964
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-slot` directives
|
|
2965
|
+
|
|
2966
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2967
|
+
- 自动修复:不支持或上游未声明
|
|
2968
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-slot.html)
|
|
2969
|
+
- 常见报告:`'v-slot' directive must be owned by a custom element, but '{{name}}' is not.`;`Named slots must use '<template>' on a custom element.`;`Default slot must use '<template>' on a custom element when there are other named slots.`
|
|
2970
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2971
|
+
|
|
2972
|
+
错误示例:
|
|
2973
|
+
|
|
2974
|
+
<!-- prettier-ignore -->
|
|
2975
|
+
````vue
|
|
2976
|
+
<template>
|
|
2977
|
+
<div #header>Title</div>
|
|
2978
|
+
</template>
|
|
2979
|
+
````
|
|
2980
|
+
|
|
2981
|
+
正确示例:
|
|
2982
|
+
|
|
2983
|
+
<!-- prettier-ignore -->
|
|
2984
|
+
````vue
|
|
2985
|
+
<template>
|
|
2986
|
+
<UserCard><template #header>Title</template></UserCard>
|
|
2987
|
+
</template>
|
|
2988
|
+
````
|
|
2989
|
+
|
|
2990
|
+
### `vue/valid-v-text`
|
|
2991
|
+
|
|
2992
|
+
校验对应语法、属性或参数是否合法。上游说明:enforce valid `v-text` directives
|
|
2993
|
+
|
|
2994
|
+
- 生效级别与范围:error: Vue SFC、UniApp NVue
|
|
2995
|
+
- 自动修复:不支持或上游未声明
|
|
2996
|
+
- 规则来源:[官方文档](https://eslint.vuejs.org/rules/valid-v-text.html)
|
|
2997
|
+
- 常见报告:`'v-text' directives require no argument.`;`'v-text' directives require no modifier.`;`'v-text' directives require that attribute value.`
|
|
2998
|
+
- 示例类型:第三方预置规则的直接代码示例
|
|
2999
|
+
|
|
3000
|
+
错误示例:
|
|
3001
|
+
|
|
3002
|
+
<!-- prettier-ignore -->
|
|
3003
|
+
````vue
|
|
3004
|
+
<template>
|
|
3005
|
+
<p v-text />
|
|
3006
|
+
</template>
|
|
3007
|
+
````
|
|
3008
|
+
|
|
3009
|
+
正确示例:
|
|
3010
|
+
|
|
3011
|
+
<!-- prettier-ignore -->
|
|
3012
|
+
````vue
|
|
3013
|
+
<template>
|
|
3014
|
+
<p v-text="message" />
|
|
3015
|
+
</template>
|
|
3016
|
+
````
|