Skip to content

Docs/162 fragments #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ const sidebar = {
'migration/v-model',
'migration/functional-components',
'migration/async-components',
'migration/custom-directives'
'migration/custom-directives',
'migration/fragments'
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/guide/component-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ app.component('custom-layout', {
template: `
<header>...</header>
<main v-bind="$attrs">...</main>
<footer...></footer>
<footer>...</footer>
`
})
```
Expand Down
41 changes: 41 additions & 0 deletions src/guide/migration/fragments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Fragments

## Overview

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

## Previous 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.

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

## Current Syntax

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

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

<script>
export default {
inheritAttrs: false
}
</script>
```

For more information on how attribute inheritance works, see [Non-Prop Attributes](/guide/component-props.html#disabling-attribute-inheritance).