Skip to content

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 2 commits into from
Nov 4, 2020

Conversation

NataliaTepluhina
Copy link
Member

@NataliaTepluhina NataliaTepluhina commented Nov 3, 2020

$children instance property is removed but this removal is not documented. This PR adds a required change to Migration guide

Close #454

Copy link
Member

@LinusBorg LinusBorg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. I commented a bit bout edge cases that we might want to provide guidance for, but we can consider adding that later and getting this info online first.


## 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).
Copy link
Member

@LinusBorg LinusBorg Nov 3, 2020

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:

<tabs>
  <tab  name="B" />
  <tab name="B" />
</tabs>

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?

  • One way would be to provide a ref function (like for v-for) through v-slot props, but that's not really ergonomic.
  • Provide/inject can be used to make children register themselves with the parent.
    • that pattern could even be wrapped in a mixin /comp-Function to simulate $childrenbehaviour

Copy link
Member Author

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 👍

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

@NataliaTepluhina NataliaTepluhina merged commit 43a0037 into master Nov 4, 2020
nick-lai pushed a commit to nick-lai/docs-next that referenced this pull request Dec 2, 2020
* feat: added children to migration guide

* feat: added link to migration introduction
@NataliaTepluhina NataliaTepluhina deleted the remove-children branch February 24, 2021 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document removal of $children API
3 participants