从非 vue 文件访问 vue 3 应用实例 api [英] access vue 3 app instance api from non-vue fiile
本文介绍了从非 vue 文件访问 vue 3 应用实例 api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 vue 2 中,您可以像这样从 .js 文件访问 Vue 实例全局 api:
In vue 2 you can access the Vue instance Global api from .js files like this:
Vue.prototype.$auth
在 Vue 3 中你有应用程序实例,据我所知它现在只存在于 main.js 中
in Vue 3 you have the app instance, which as far as I know right now only exists within main.js
例如,如果我有 helper.js,我如何从帮助文件中访问 app.config.globalProperties.$auth
?
so if for instance, I have helper.js, how do I access app.config.globalProperties.$auth
from the help file?
推荐答案
尝试从 main.js
和在您的 helper.js
文件中使用它:
Try to export the app
instance from the main.js
and use it in your helper.js
file :
导出应用程序;
helpers.js
import {app} from './main'
或者您可以在任何组件内调用辅助函数时传递该全局变量.
or you could pass that global variable when you call the helper function inside any component.
这篇关于从非 vue 文件访问 vue 3 应用实例 api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文