How can I use all those vue functions defined in 'setup' outside a ts file? #7996
Unanswered
Richard20230331
asked this question in
Help/Questions
Replies: 2 comments 8 replies
-
//myTs.ts
import { getCurrentInstance } from 'vue';
export function jsFunction(){
const { proxy } = getCurrentInstance();
console.log(proxy);
} |
Beta Was this translation helpful? Give feedback.
7 replies
-
I would strongly recommend to not pass the component instance around. Pass the actual functions. I know that would be tiresome if it was 100 functions, but then you likely need to refactor something anyway. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How can I use all those vue functions defined in 'setup' outside a ts file?
Here is my example:
// myVue.vue
//myTs.ts
Let's say I have plenty of functions (like 100) that required to be launched in myTs.ts which are defined
in myVue.vue in "setup" tag. I tried to transfer the proxy of getCurrentInstance() to myTs.ts, wishing that I
could find those functions in it but failed.
So I wonder where are those functions in 'setup' tag registered in vue? How can I find them all and use them
in myTs.ts?
P.S.: One way I know is to transfer those functions by setting them as the parameters of jsFunction(functions),
but the fact is that I have a lot of functions and I wish that I could find a vue object that contains them all,
so I only need to set 1 parameter.
Beta Was this translation helpful? Give feedback.
All reactions