How to obtain component instances in <script setup> #9092
Unanswered
FatNerdPeng
asked this question in
Help/Questions
Replies: 2 comments 4 replies
-
<script lang="ts" setup>
import { getCurrentInstance } from 'vue';
const instance = getCurrentInstance();
</script> |
Beta Was this translation helpful? Give feedback.
2 replies
-
I'd be interested to understand the usecase, that would make it easier to give a proper recommendation |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,I couldn't find how to obtain component instances under <script setup> syntax sugar in the official document. Can someone guide me? I have checked some information and it is said that the getCurrentInstance() method is used, but this method is not in the official documentation, and it is a method from Vue2, which may be discarded in the future. The official document provides a set of optional API functions to obtain properties on components, but my requirement is to obtain the context of component instances. I was unable to find any methods in the document, which caused me a headache. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions