Skip to content

rule: no accessing computed properties in data #1470

Closed
@privatenumber

Description

@privatenumber

Please describe what the rule should do:

Should warn when accessing a computed property from the data() function, as computed properties are not initialized at that point and returns undefined.

Vue 2 demo: https://jsfiddle.net/hirokiosame/dunkzqL0/7/
Vue 3 demo: https://jsfiddle.net/hirokiosame/4qu8yxfo/2/

What category should the rule belong to?

[ ] Enforces code style (layout)
[x] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

<script>
export default {
    computed: {
        defaultValue() {
            return 123;
        }
    },
    data() {
        return {
            // computed not initialized yet, so returns undefined
            someValue: this.defaultValue,
        };
    },
};
</script>

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions