In Vuejs 2 we can use global variables like this:
in main.js
import Vue from 'vue'
import App from './App.vue'
import Axios from 'axios';
Vue.prototype.$http = Axios;
Then we can use
in App.vue
this.$http.get('somethings')
But in Vuejs 3 I have tried
import { createApp } from 'vue'
import App from './App.vue'
import Axios from 'axios';
const app = createApp(App)
app.prototype.$http = Axios;
It's show me can't set $http of undefiend.
How can I set global variables in Vuejs 3?
In Vuejs 2 we can use global variables like this:
in main.js
import Vue from 'vue'import App from './App.vue'import Axios from 'axios';Vue.prototype.$http = Axios;Then we can use
in App.vue
this.$http.get('somethings')But in Vuejs 3 I have tried
import { createApp } from 'vue'import App from './App.vue'import Axios from 'axios';const app = createApp(App)app.prototype.$http = Axios;It's show me can't set $http of undefiend.
How can I set global variables in Vuejs 3?