Hi @yaazel tryout this link, I guess it has the answer to you question
Oct 22, 2022
3
Level 1
How to use a function in any component without explicitly importing it in vue3
Hello,
How to use a function in any component without explicitly importing it in vue3?
I'm thinking, if I import in app.js it can be accessed in every component. But its not working.
This is how I'm doing it:
Say I've a function in @/myjs/myfunctions.js
export function myfunc(){
//
}
in app.js
import {myfunc} from '@/myjs/myfunction'
But its not accessible in every component. What to do?
Level 1
For any one wondering how to do this.
In vue there are only 3 ways of having global functions (to be used across all components)
- Mixins (not recommended in vue3)
- Plugins (make your function a plugin and use that plugin)
- Composables (recommended way in vue3)
Please or to participate in this conversation.