Skip to content
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

Can't get componentInstance property of vnode when using the v-slot directive on a <template>. #11464

Closed
xiejay97 opened this issue Jun 18, 2020 · 3 comments

Comments

@xiejay97
Copy link

xiejay97 commented Jun 18, 2020

Version

2.6.11

Reproduction link

https://github.com/Xie-Jay/slot-issue

Steps to reproduce

I show issue by console.

What is expected?

All vnode can get componentInstance property.

What is actually happening?

ComponentInstance property is undefined when using the v-slot directive, but others not.

<slot-test>
  <component-test slot="default" name="slot1"></component-test>
</slot-test>
<slot-test>
  <template slot="default">
    <component-test name="slot2"></component-test>
  </template>
</slot-test>
<slot-test>
  <template v-slot:default>
    <component-test name="slot3"></component-test>
  </template>
</slot-test>

image


When I use v-slot to replace slot, I get this diffrence which really confuse me.

@posva
Copy link
Member

posva commented Jun 18, 2020

I'm not sure you are supposed to use componentInstance from the returned vnode. You can still get the component instance through $children[0]

@xiejay97
Copy link
Author

xiejay97 commented Jun 18, 2020

I'm not sure you are supposed to use componentInstance from the returned vnode. You can still get the component instance through $children[0]

It's useful for me to build component that need control components in slot by using componentInstance.

I tried to use $children, it's ok when just one slot.

But more than one, like this:

<div>
  <slot />
  <slot name="expand" />
</div>

It will be difficult to separate these components in slot by using $children.

In fact, I have no idea except that provide extra prop to distinguish them, because there’s no order guarantee for $children.

@hanotao
Copy link

hanotao commented Aug 26, 2020

@rubys @rubys @rubys @rubys 666

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

No branches or pull requests

3 participants