Skip to content

noVueDuplicateKeys

biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueDuplicateKeys": "error"
}
}
}
}

Disallow duplicate keys in Vue component data, methods, computed properties, and other options.

This rule prevents the use of duplicate keys across different Vue component options such as props, data, computed, methods, and setup. Even if keys don’t conflict in the script tag, they may cause issues in the template since Vue allows direct access to these keys.

<script>
export default {
props: ['foo'],
data() {
return {
foo: 'bar'
};
}
};
</script>
code-block.vue:2:13 lint/nursery/noVueDuplicateKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Duplicate key foo found in Vue component.

1 │ export default {
> 2 │ props: [‘foo’],
^^^^^
3 │ data() {
4 │ return {

Key foo is also defined here.

3 │ data() {
4 │ return {
> 5 │ foo: ‘bar’
^^^
6 │ };
7 │ }

Keys defined in different Vue component options (props, data, methods, computed) can conflict when accessed in the template. Rename the key to avoid conflicts.

<script>
export default {
data() {
return {
message: 'hello'
};
},
methods: {
message() {
console.log('duplicate key');
}
}
};
</script>
code-block.vue:4:13 lint/nursery/noVueDuplicateKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Duplicate key message found in Vue component.

2 │ data() {
3 │ return {
> 4 │ message: ‘hello’
^^^^^^^
5 │ };
6 │ },

Key message is also defined here.

6 │ },
7 │ methods: {
> 8 │ message() {
^^^^^^^
9 │ console.log(‘duplicate key’);
10 │ }

Keys defined in different Vue component options (props, data, methods, computed) can conflict when accessed in the template. Rename the key to avoid conflicts.

<script>
export default {
computed: {
count() {
return this.value * 2;
}
},
methods: {
count() {
this.value++;
}
}
};
</script>
code-block.vue:3:9 lint/nursery/noVueDuplicateKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Duplicate key count found in Vue component.

1 │ export default {
2 │ computed: {
> 3 │ count() {
^^^^^
4 │ return this.value * 2;
5 │ }

Key count is also defined here.

6 │ },
7 │ methods: {
> 8 │ count() {
^^^^^
9 │ this.value++;
10 │ }

Keys defined in different Vue component options (props, data, methods, computed) can conflict when accessed in the template. Rename the key to avoid conflicts.

<script>
export default {
props: ['foo'],
data() {
return {
bar: 'baz'
};
},
methods: {
handleClick() {
console.log('unique key');
}
}
};
</script>
<script>
export default {
computed: {
displayMessage() {
return this.message.toUpperCase();
}
},
methods: {
clearMessage() {
this.message = '';
}
}
};
</script>