Skip to content

Commit 919c8d9

Browse files
committed
docs (#162): add fragments to migration section
1 parent 7ebaed9 commit 919c8d9

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/.vuepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ const sidebar = {
9393
'migration/v-model',
9494
'migration/functional-components',
9595
'migration/async-components',
96-
'migration/custom-directives'
96+
'migration/custom-directives',
97+
'migration/fragments'
9798
]
9899
},
99100
{

src/guide/migration/fragments.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Fragments
2+
3+
## Overview
4+
5+
In Vue 3, components now have official support for multi-root node components, i.e., fragments!
6+
7+
## Previous Syntax
8+
9+
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.
10+
11+
```html
12+
// Layout.vue
13+
<template>
14+
<div>
15+
<header>...</header>
16+
<main>...</main>
17+
<footer>...</footer>
18+
</div>
19+
</template>
20+
```
21+
22+
## Current Syntax
23+
24+
In 3.x, components now can have multiple root nodes! However, this does require developers to explicitly define where attributes should be distributed.
25+
26+
```html
27+
<!-- Layout.vue -->
28+
<template>
29+
<header>...</header>
30+
<main v-bind="$attrs">...</main>
31+
<footer>...</footer>
32+
</template>
33+
34+
<script>
35+
export default {
36+
inheritAttrs: false
37+
}
38+
</script>
39+
```
40+
41+
For more information on how attribute inheritance works, see [Non-Prop Attributes](/guide/component-props.html#disabling-attribute-inheritance).

0 commit comments

Comments
 (0)