noVueComputedPropertiesInData (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.4 - Diagnostic Category:
lint/nursery/noVueComputedPropertiesInData - 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": { "noVueComputedPropertiesInData": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<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>Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.