vue/return-in-computed-property
enforce that a return statement is present in computed property
- ⚙️ This rule is included in all of
"plugin:vue/essential"
,"plugin:vue/strongly-recommended"
and"plugin:vue/recommended"
.
📖 Rule Details
This rule enforces that a return
statement is present in computed
properties.
<script>
export default {
computed: {
/* ✓ GOOD */
foo () {
if (this.bar) {
return this.baz
} else {
return this.baf
}
},
bar: function () {
return false
},
/* ✗ BAD */
baz () {
if (this.baf) {
return this.baf
}
},
baf: function () {}
}
}
</script>
🔧 Options
{
"vue/return-in-computed-property": ["error", {
"treatUndefinedAsUnspecified": true
}]
}
This rule has an object option:
"treatUndefinedAsUnspecified"
:true
(default) disallows implicitly returning undefined with areturn
statement.
treatUndefinedAsUnspecified: false
<script>
export default {
computed: {
/* ✓ GOOD */
foo () {
if (this.bar) {
return undefined
} else {
return
}
},
bar: function () {
return
},
/* ✗ BAD */
baz () {
if (this.baf) {
return this.baf
}
},
baf: function () {}
}
}
</script>