W3cubDocs

/Vue.js 3

Fragments
new

Overview

In Vue 3, components now have official support for multi-root node components, i.e., fragments!

2.x Syntax

In 2.x, multi-root components were not supported and would emit a warning when a user accidentally created one. As a result, many components are wrapped in a single <div> in order to fix this error.

<!-- Layout.vue -->
<template>
  <div>
    <header>...</header>
    <main>...</main>
    <footer>...</footer>
  </div>
</template>

3.x Syntax

In 3.x, components now can have multiple root nodes! However, this does require developers to explicitly define where attributes should be distributed.

<!-- Layout.vue -->
<template>
  <header>...</header>
  <main v-bind="$attrs">...</main>
  <footer>...</footer>
</template>

For more information on how attribute inheritance works, see Non-Prop Attributes.

© 2013–present Yuxi Evan You
Licensed under the MIT License.
https://v3.vuejs.org/guide/migration/fragments