我在Vue3项目中定义了一些全局变量,如:
app.config.globalproperties.$locale = locale
然后创建Composable以动态返回全局变量:
import { getCurrentInstance ) from 'vue'
export function useGlobals(type) {
const app = getCurrentInstance()
const global = app.appContext.config.globalProperties[`$${type}`]
return { global }
}
然后在VUE中,可组合的组件被导入并执行:
import { useGlobals } from '../path'
const { global } = useGlobals('locale')
现在,可以使用全局变量.
但当我在js
个文件中导入Composable时出现了问题,那里的appContext
是未定义的.
我的问题是,有没有办法在js
个文件中获得全局变量或appContext
?