Warn on using v-if on the template root node, because:
Whether a component should be rendered or not is a usage concern. Specifically, it's confusing when a declared component is not rendered:
/* Usage */
<template><div>
...
<custom-component /> /* Readers expect this to be rendered */
</div></template>
/* CustomComponent.vue */
<template><divv-if="false">
...
</div></template>
There are performance benefits:
Instantiating a new stateful component only for it to not be rendered via root v-if="false" is wasteful. If possible, it should happen in the parent usage life-cycle.
When moving the v-if to the parent, the component can be asynchronously loaded when needed, so not only will it save on component registration, it will save on module declaration and asset size.
[ ] Enforces code style (layout)
[ ] Warns about a potential error (problem)
[x] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule should warn about:
Please describe what the rule should do:
Warn on using
v-if
on the template root node, because:Whether a component should be rendered or not is a usage concern. Specifically, it's confusing when a declared component is not rendered:
There are performance benefits:
v-if="false"
is wasteful. If possible, it should happen in the parent usage life-cycle.v-if
to the parent, the component can be asynchronously loaded when needed, so not only will it save on component registration, it will save on module declaration and asset size.What category should the rule belong to?
[ ] Enforces code style (layout)
[ ] Warns about a potential error (problem)
[x] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule should warn about:
Bad
Good
Additional context
The text was updated successfully, but these errors were encountered: