-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Document removal of $children API on Migration guide #670
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
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
badges: | ||
- removed | ||
--- | ||
|
||
# $children <MigrationBadges :badges="$frontmatter.badges" /> | ||
|
||
## Overview | ||
|
||
`$children` instance property removed from Vue 3.0 and no longer supported. | ||
|
||
## 2.x Syntax | ||
|
||
In 2.x, developers could access direct child components of the current instance with `this.$children`: | ||
|
||
```html | ||
<div ref="app" id="app"> | ||
<img alt="Vue logo" src="./assets/logo.png" width="25%" /> | ||
<my-button>Change logo</my-button> | ||
</div> | ||
``` | ||
|
||
```js | ||
export default { | ||
name: "App", | ||
components: { | ||
MyButton, | ||
}, | ||
mounted() { | ||
console.log(this.$children); // [VueComponent] | ||
}, | ||
}; | ||
</script> | ||
``` | ||
|
||
## 3.x Update | ||
|
||
In 3.x, `$children` property is removed and no longer supported. Instead, if you need to access a child component instance, we recommend using [$refs](/guide/component-template-refs.html#template-refs). | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
refs only work in a straightforward way when accessing children in a component's own template.
However, I think there are quite a few plugins out there that rely on
$children
in order to access child components in slots - think of a compound component like this:It's not a particularly good pattern in my opinion as you could easily end up with children that you don't expect, but it seems it's used in the community.
Can we provide some guidance how to avoid such a pattern?
v-for
) throughv-slot
props, but that's not really ergonomic.$children
behaviourThere 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.
@LinusBorg, I agree with the addition but (as you mentioned in he above comment) let's add it in the follow-up PR 👍
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.
would love to see guidance on this pattern please