noVueReservedKeys
¥Summary
-
规则生效日期:
v2.1.3¥Rule available since:
v2.1.3 -
诊断类别:
lint/nursery/noVueReservedKeys¥Diagnostic Category:
lint/nursery/noVueReservedKeys -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
此规则属于以下域:
¥This rule belongs to the following domains:
-
来源:
¥Sources:
-
与
vue/no-reserved-keys相同¥Same as
vue/no-reserved-keys
-
¥How to configure
{ "linter": { "rules": { "nursery": { "noVueReservedKeys": "error" } } }}¥Description
禁止在 Vue 组件数据和计算属性中使用保留键。
¥Disallow reserved keys in Vue component data and computed properties.
Vue 保留某些键供其内部使用。在数据属性、计算属性、方法或其他组件选项中使用这些保留键可能会导致 Vue 组件出现冲突和不可预测的行为。
¥Vue reserves certain keys for its internal use. Using these reserved keys in data properties, computed properties, methods, or other component options can cause conflicts and unpredictable behavior in your Vue components.
此规则禁止使用 Vue 保留键,例如:
¥This rule prevents the use of Vue reserved keys such as:
-
以
$开头的键(例如,$el、$data、$props、$refs等)¥Keys starting with
$(e.g.,$el,$data,$props,$refs, etc.) -
数据属性中以
_开头的键(保留给 Vue 内部使用)¥Keys starting with
_in data properties (reserved for Vue internals)
¥Examples
¥Invalid
<script>export default { data: { $el: '', },};</script>code-block.vue:3:9 lint/nursery/noVueReservedKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Key $el is reserved in Vue.
1 │ export default {
2 │ data: {
> 3 │ $el: ”,
│ ^^^
4 │ },
5 │ };
ℹ Rename the key to avoid conflicts with Vue reserved keys.
<script>export default { data() { return { _foo: 'bar', }; },};</script>code-block.vue:4:13 lint/nursery/noVueReservedKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Keys starting with an underscore are reserved in Vue.
2 │ data() {
3 │ return {
> 4 │ _foo: ‘bar’,
│ ^^^^
5 │ };
6 │ },
ℹ Rename the key to avoid conflicts with Vue reserved keys.
<script>export default { computed: { $data() { return this.someData; }, },};</script>code-block.vue:3:9 lint/nursery/noVueReservedKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Key $data is reserved in Vue.
1 │ export default {
2 │ computed: {
> 3 │ $data() {
│ ^^^^^
4 │ return this.someData;
5 │ },
ℹ Rename the key to avoid conflicts with Vue reserved keys.
<script>export default { methods: { $emit() { // This conflicts with Vue's built-in $emit }, },};</script>code-block.vue:3:9 lint/nursery/noVueReservedKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Key $emit is reserved in Vue.
1 │ export default {
2 │ methods: {
> 3 │ $emit() {
│ ^^^^^
4 │ // This conflicts with Vue’s built-in $emit
5 │ },
ℹ Rename the key to avoid conflicts with Vue reserved keys.
¥Valid
<script>export default { data() { return { message: 'Hello Vue!', count: 0, }; },};</script><script>export default { computed: { displayMessage() { return this.message; }, },};</script>¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号