Skip to content

Allow functional components to have multiple root elements #1168

Open
@euoia

Description

@euoia

What problem does this feature solve?

As discussed in vuejs/vue#7088 multiple root elements are not currently possible in Vue components, with @LinusBorg stating that multiple root elements will not be supported (in the general case) any time soon.

The exception to this is for functional components, where multiple root elements are allowed. Here's a jsfiddle from @trusktr showing it, though using a render function:
https://jsfiddle.net/b049qboe/1/

This feature would allow multiple root elements in elements used in single-file components. Vue-loader 14.1.1 produces the following error in this scenario:

  - Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.

What does the proposed API look like?

In a single-file component:

<template functional>
    <!-- Multiple root elements, e.g. -->
    <div>lorum</div>
    <div>ipsum</div>
    <div>dolor</div>
</template>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions