Return value of function-typed Vue options should be a valid type
- VUE_BAD_API_RETURN_VALUE
- Error
- Medium
- vue
This rule applies when the return value of a function-typed Vue option is invalid.
If an invalid value is returned from a function-typed Vue option, it may cause a problem when Vue uses the value. Even when no immediate problem occurs, the value becomes meaningless.
The options which cause problem for an invalid return value are listed below with the valid return values:
data()
:Object
setup()
:Object
,Function
, orundefined
render()
for non-functional components: any value exceptArray
(Vue 2.x only)renderError()
: any value exceptArray
errorCaptured()
lifecycle hook:false
,undefined
, ornull
Vue outputs a warning message in the cases of data()
, render()
, and renderError()
.
Also, this rule checks the following lifecycle hooks which need no return value:
beforeCreate()
created()
beforeMount()
mounted()
beforeUpdate()
updated()
activated()
deactivated()
beforeDestroy()
(Vue 2.x) orbeforeUnmount()
(Vue 3.x)destroyed()
(Vue 2.x) orunmounted()
(Vue 3.x)renderTracked()
renderTriggered()
In the above cases, returning a value has no effect.
Noncompliant Code Example
View with compliant examples side by side<script>
export default {
data() {
return 'data'; // VUE_BAD_API_RETURN_VALUE alarm because 'data()' does not return an object.
},
beforeCreate() {
return true; // VUE_BAD_API_RETURN_VALUE alarm because 'beforeCreate()' does not need a return value.
}
}
</script>
Compliant Code Example
View with noncompliant examples side by side<script>
export default {
data() {
return { msg: 'hi' };
},
beforeCreate() {
// do something
}
}
</script>
Version
This rule was introduced in DeepScan 1.14.0-beta.