Skip to content

Declare global variable for all components #466

@ammasum

Description

@ammasum

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions