如何将对象安装在vue2.7实例上?
我刚刚将项目完全升级到VUE2.7,该项目对VUE3功能提供了支持。
就像我尝试的是,在vue实例链中获取对象,例如 从“ vue”导入vue; vue.protype。$ http = http;
,但没有任何方法或挂钩,例如createApp
vue2.7中支持的,所以我如何访问它($ http )在我的组件中?
我暂时只能做console.log(getCurrentInstance())
。
最后,通过getCurrentInstance()。代理。__proto __.__ proto __。$ http
,例如不愉快的代码,是否有其他更好的快捷方式?谢谢。
I have just completely upgraded my project to Vue2.7, which a backported support for Vue3 feature.
Like what I try is, get the object the in vue instance chain, such asimport Vue from 'vue'; Vue.prototype.$http = http;
but no any method or hook such as createApp
supported in vue2.7, so how to I access it(the $http
) in my component?
only what I can do for now just console.log(getCurrentInstance())
.
And finally get it by getCurrentInstance().proxy.__proto__.__proto__.$http
, such unpleasant code, is it any other better shortcut to do this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用
提供/注入
使所有组件中的Axios可用。https://vuejs.org/guide/components/components/provide-inject.html
I would suggest using
provide/inject
to make the axios available in all your components.https://vuejs.org/guide/components/provide-inject.html
通过热心的人jacek来找出路,只需使用提供和
注入
来解决它。一样
Find out the way by warmed-heart people Jacek, just use
provide
andinject
to solve it.Just like