noVueDeprecatedPropsDefaultThis (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.5 - Diagnostic Category:
lint/nursery/noVueDeprecatedPropsDefaultThis - This rule doesn’t have a fix.
- The default severity of this rule is error.
- This rule belongs to the following domains:
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noVueDeprecatedPropsDefaultThis": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<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>Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.