Skip to content

noVueComputedPropertiesInData (JavaScript)

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

Disallow using computed properties inside the data function of a Vue component.

Vue runs the data function before it sets up the component’s computed properties. Reading a computed property there through this gives undefined instead of the computed value.

Only code written directly in data is checked. Code inside a function created in data, such as an arrow function stored as a data property, is not reported.

<script>
export default {
data() {
return {
total: this.doubled,
};
},
computed: {
doubled() {
return 2;
},
},
};
</script>
code-block.vue:5:14 lint/nursery/noVueComputedPropertiesInData ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The computed property doubled is used inside the data function.

3 │ data() {
4 │ return {
> 5 │ total: this.doubled,
│ ^^^^^^^^^^^^
6 │ };
7 │ },

ℹ The computed property is declared here.

7 │ },
8 │ computed: {
> 9 │ doubled() {
│ ^^^^^^^
10 │ return 2;
11 │ },

ℹ Vue runs the data function before it sets up computed properties, so this value is undefined.

ℹ Compute the value from props or other data instead, or turn this data property into a computed property.

ℹ 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: ["initial"],
data() {
return {
count: this.initial,
label: this.formatLabel(),
read: () => this.doubled,
};
},
computed: {
doubled() {
return this.count * 2;
},
},
methods: {
formatLabel() {
return "Count";
},
},
};
</script>