Home > Blockchain >  How can get Object mounted on vue2.7 instance?
How can get Object mounted on vue2.7 instance?

Time:07-06

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 as import 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.

CodePudding user response:

I would suggest using provide/inject to make the axios available in all your components.

https://vuejs.org/guide/components/provide-inject.html

CodePudding user response:

Find out the way by warmed-heart people Jacek, just use provide and inject to solve it.

Just like

const vue = new Vue({
  setup() {
    provide('http', http)
  }, ...
}
  • Related