Skip to content

noVueDeprecatedPropsDefaultThis (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueDeprecatedPropsDefaultThis": "error"
}
}
}
}

Disallow this in the default value function of a Vue prop.

When a prop expects an object or an array, its default value is written as a function that returns that value. Vue doesn’t give this function access to the component, so this doesn’t point to the component inside it. Reading another prop with this.name fails. The function receives the props passed to the component as its first argument, so read other props from that argument instead.

Props whose type is Function aren’t checked, because Vue uses their default value as the function itself instead of calling it.

See the Vue 3 migration guide for more information.

<script>
export default {
props: {
size: Number,
sizes: {
type: Array,
default() {
return [this.size];
},
},
},
};
</script>
code-block.vue:8:17 lint/nursery/noVueDeprecatedPropsDefaultThis ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ this is used in the default value function of a prop.

6 │ type: Array,
7 │ default() {
> 8 │ return [this.size];
│ ^^^^
9 │ },
10 │ },

ℹ Vue doesn't give this function access to the component, so this doesn't point to the component.

ℹ Read other props from the first argument of the function instead, for example default(props) { return props.size }.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<script>
export default {
props: {
size: Number,
sizes: {
type: Array,
default(props) {
return [props.size];
},
},
onSelect: {
type: Function,
default() {
console.log(this.size);
},
},
},
};
</script>