Skip to content

"Multiple" root components could be allowed if v-if and v-else are used #3878

@aphofstede

Description

@aphofstede

Vue.js version

2.0.1

Reproduction Link

https://jsfiddle.net/alexman/h64y6bj1/1/

Steps to reproduce

Set up a standalone component with template:

<template>
    <div v-if="isComplex"><slot></slot></div>
    <button v-else><slot></slot></button>
</template>

And computed field:

  computed: {
    isComplex() {
            return false // true
        }
  }

What is Expected?

v-if with a v-else following it resolves to exactly 1 component, so I believe it could be allowed and not throw an error about a missing root component.
Making isComplex() return true in the example should display a div, and false would display a button.

What is actually happening?

Component template should contain exactly one root element:

<div v-if="isComplex"><slot></slot></div>
<button v-else><slot></slot></button>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions