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

Missing search result for getCurrentInstancegetCurrentInstance #2335

Closed
sm200435 opened this issue Apr 24, 2023 · 4 comments
Closed

Missing search result for getCurrentInstancegetCurrentInstance #2335

sm200435 opened this issue Apr 24, 2023 · 4 comments

Comments

@sm200435
Copy link

官网搜索不到getCurrentInstance()

@viniciusteixeiradias
Copy link

官网搜索不到getCurrentInstance()

#1422 (comment)

@yyx990803
Copy link
Member

It is intentionally omitted to discourage its usage.

@jackchoumine
Copy link

jackchoumine commented Aug 9, 2023

It is intentionally omitted to discourage its usage.

If so, How can I get $el?

const that = getCurrentInstance()
const ele = that.ctx.$el // work well in vue3.1.x but  get undefined in vue3.3.4

@viniciusteixeiradias
Copy link

viniciusteixeiradias commented Aug 9, 2023

It is intentionally omitted to discourage its usage.

If so, How can I get $el?

const that = getCurrentInstance()
const ele = that.ctx.$el // work well in vue3.1.x but  get undefined in vue3.3.4

Directly accessing the internal properties of Vue components, such as $el, is generally not recommended. It's considered a best practice to avoid manipulating internal properties directly, as it can lead to issues and might not be compatible with different versions or future updates.

If you need to access the root element of the component, Vue provides a more reliable approach using theref attribute or maybe you could take a look at https://vuejs.org/api/composition-api-setup.html#setup-context

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

4 participants