-
Notifications
You must be signed in to change notification settings - Fork 4.7k
docs (#151): add slots unification section to migration guide #159
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d7a17c9
docs (#151): add slots unification section to migration guide
bencodezen b6004f0
fix: typo
bencodezen 2dea1bc
Merge branch 'master' into docs/151-slots-unification
bencodezen a0d5bd2
Merge branch 'docs/151-slots-unification' of github.com:vuejs/docs-ne…
bencodezen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Slots Unification | ||
|
||
## Overview | ||
|
||
This change unifies normal and scoped slots in v3. | ||
|
||
Here is a quick summary of what has changed: | ||
|
||
- `this.$slots` now exposes slots as functions | ||
- **BREAKING**: `this.$scopedSlots` is removed | ||
|
||
For more information, read on! | ||
|
||
## Previous Syntax | ||
|
||
When using the render function, i.e., `h`, v2 used to define the `slot` data property on the content nodes. | ||
|
||
```js | ||
// 2.x Syntax | ||
h(LayoutComponent, [ | ||
h('div', { slot: 'header' }, this.header), | ||
h('div', { slot: 'content' }, this.content) | ||
]) | ||
``` | ||
|
||
In addition, when referencing scoped slots, they could be referenced using the following syntax: | ||
|
||
```js | ||
// 2.x Syntax | ||
this.$scopedSlots.header | ||
``` | ||
|
||
## Current Syntax | ||
|
||
In v3, render functions will have a `slots` option where they can be defined instead. | ||
|
||
```js | ||
// 3.x Syntax | ||
h(LayoutComponent, { | ||
slots: { | ||
header: () => h('div', this.header), | ||
content: () => h('div', this.content) | ||
} | ||
}) | ||
``` | ||
|
||
And when you need to reference scoped slots programmatically, they are now unified into the `$slots` option. | ||
|
||
```js | ||
// 2.x Syntax | ||
this.$scopedSlots.header | ||
|
||
// 3.x Syntax | ||
this.$slots.header | ||
``` | ||
|
||
## Migration Strategy | ||
|
||
A majority of the change has already been shipped in 2.6. As a result, the migration can happen in one step: | ||
|
||
1. Replace all `this.$scopedSlots` occurrences with `this.$slots` in v3. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: let's define the consistent name for this section! On other PRs you called it
How to Migrate
(and I used the same forv-model
), what option would you prefer to keep?