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 access ref correctly if component was imported by defineAsyncComponent() #2671

Closed
ShookLyngs opened this issue Nov 26, 2020 · 3 comments
Labels
🐞 bug Something isn't working

Comments

@ShookLyngs
Copy link

Version

3.0.3

Reproduction link

https://codepen.io/ShookLyngs/pen/gOwObGG

Steps to reproduce

  1. import component by using defineAsyncComponent(), for example component item
  2. define ref in template, for example <item ref="item" />
  3. access ref in manual event callback, like @click
  4. access funcion in component item
  5. using this.$refs.item.do(), fail
  6. using this.$refs.item.$refs.item.do(), success

What is expected?

access ref by this.$refs.item.

What is actually happening?

have to access ref by using this.$refs.item.$refs.item.

@posva posva added the 🐞 bug Something isn't working label Nov 26, 2020
@posva
Copy link
Member

posva commented Nov 26, 2020

Looks like the ref is pointing to the AsyncWrapper instead

@ShookLyngs
Copy link
Author

Looks like the ref is pointing to the AsyncWrapper instead

Yes, and if I have a component item, its content is simply:

<template>
  <slot />
</template>

Then when I use this component,
and pass a async-component to fill the slot:

<item>
  <async-component />
</item>

In component item, I tried to get this.$el in mounted() or in $nextTick(), but it just won't work.
What can I do to get the content of component item?

@yyx990803
Copy link
Member

ref on async component should be fixed by the commit above, but since it's async, you can't just access this.$el in mounted anyway. You'll have to wait until the async component is actually loaded (which can take unknown amount of time). So you should use a ref (after the fix is released).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants