I have some global variables in Vue3 project defined like:
app.config.globalproperties.$locale = locale
then composable is created to dynamically return global variable:
import { getCurrentInstance ) from 'vue'
export function useGlobals(type) {
const app = getCurrentInstance()
const global = app.appContext.config.globalProperties[`$${type}`]
return { global }
}
then in vue components composable is imported and executed:
import { useGlobals } from '../path'
const { global } = useGlobals('locale')
now, global variable can be used.
But the problem arise when I import composable in js files, there the appContext is undefined.
My question is, is there a way we can get global variable or appContext in js files?
export const { appContext } = appinmain.js? Should work.