Skip to content

noVueReservedProps

¥Summary

¥How to configure

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

¥Description

禁止将保留名称用作 props。

¥Disallow reserved names to be used as props.

Vue 保留某些属性名称供其内部使用。将这些保留名称用作 prop 名称可能会导致 Vue 组件出现冲突和意外行为。

¥Vue reserves certain prop names for its internal use. Using these reserved names as prop names can cause conflicts and unexpected behavior in your Vue components.

此规则禁止使用以下保留属性名称:

¥This rule prevents the use of the following reserved prop names:

  • key - Vue 用于列表渲染和组件识别

    ¥key - Used by Vue for list rendering and component identification

  • ref - Vue 用于模板引用

    ¥ref - Used by Vue for template refs

¥Examples

¥Invalid

<script setup>
defineProps({
ref: String,
});
</script>
code-block.vue:2:5 lint/nursery/noVueReservedProps ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ref is a reserved attribute and cannot be used as props.

1 │ defineProps({
> 2 │ ref: String,
^^^
3 │ });
4 │

Rename the prop to avoid possible conflicts.

import {defineComponent} from 'vue';
export default defineComponent({
props: [
'key',
]
});
code-block.js:5:9 lint/nursery/noVueReservedProps ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

key is a reserved attribute and cannot be used as props.

3 │ export default defineComponent({
4 │ props: [
> 5 │ ‘key’,
^^^^^
6 │ ]
7 │ });

Rename the prop to avoid possible conflicts.

<script setup lang="ts">
defineProps<{
ref: string,
}>();
</script>
code-block.vue:2:5 lint/nursery/noVueReservedProps ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ref is a reserved attribute and cannot be used as props.

1 │ defineProps<{
> 2 │ ref: string,
^^^
3 │ }>();
4 │

Rename the prop to avoid possible conflicts.

<script>
export default {
props: {
key: String,
}
};
</script>
code-block.vue:3:9 lint/nursery/noVueReservedProps ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

key is a reserved attribute and cannot be used as props.

1 │ export default {
2 │ props: {
> 3 │ key: String,
^^^
4 │ }
5 │ };

Rename the prop to avoid possible conflicts.

¥Valid

import {defineComponent} from 'vue';
export default defineComponent({
props: ['foo']
});
<script setup>
defineProps({ foo: String });
</script>
<script setup lang="ts">
defineProps<{
foo: string,
bar: string,
}>();
</script>
<script>
export default {
props: {
foo: String,
bar: String,
}
};
</script>

¥Related links