-
-
Notifications
You must be signed in to change notification settings - Fork 681
rule: no v-if on template root #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for rule proposal! I think the following template needs to be valid. <template>
<div v-if="mode === 'a'">
...
</div>
<div v-if="mode === 'b'">
...
</div>
</template> <template>
<div v-if="loading">
...
</div>
<div v-else>
...
</div>
</template> |
Yeah that's a great point. Good catch! |
I think that this is already covered by this rule |
How so? |
I would like to work on this @ota-meshi |
Yeah, thank you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: