Skip to content

noVueRootVIf (HTML)

Language HTML
biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueRootVIf": "error"
}
}
}
}

Disallow v-if on the root element of a Vue component template.

When the only root element of a template has a v-if and no v-else, that element disappears whenever the condition is false. Making the component conditional is clearer in the parent component, by putting the v-if where the component is used.

<template>
<div v-if="visible">Content</div>
</template>
code-block.vue:2:8 lint/nursery/noVueRootVIf ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The root element of this template is conditionally rendered with v-if.

1 │ <template>
> 2 │ <div v-if="visible">Content</div>
│ ^^^^^^^^^^^^^^
3 │ </template>
4 │

ℹ When the condition is false, the root element disappears, which hides the condition from the parent component.

ℹ Move the v-if to the parent component where this component is used, or add a v-else branch.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<template>
<div v-if="visible">Content</div>
<div v-else>Fallback</div>
</template>