noVueReservedKeys
Summary
Section titled “Summary”- Rule available since:
v2.1.3
- Diagnostic Category:
lint/nursery/noVueReservedKeys
- This rule doesn’t have a fix.
- The default severity of this rule is error.
- This rule belongs to the following domains:
- Sources:
- Same as
vue/no-reserved-keys
- Same as
Description
Section titled “Description”Disallow reserved keys in Vue component data and computed properties.
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.
This rule prevents the use of Vue reserved keys such as:
- Keys starting with
$
(e.g.,$el
,$data
,$props
,$refs
, etc.) - Keys starting with
_
in data properties (reserved for Vue internals)
Examples
Section titled “Examples”Invalid
Section titled “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.
<script>export default { data() { return { message: 'Hello Vue!', count: 0, }; },};</script>
<script>export default { computed: { displayMessage() { return this.message; }, },};</script>
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noVueReservedKeys": "error" } } }}