Tag Archives: Development experience

Method of getting app. Config. Globalproperties. X directly from vue3

Suppose we define a global method in main. JS

//main.js

 app.config.globalProperties.$hello = name => {
      console.log('hello ' + name)
 }

Call this method in other pages.

//other.js

import { getCurrentInstance } from "vue";
const { appContext } = getCurrentInstance();

const callHello = ()=>{
 appContext.config.globalProperties.$hello('jay');
}

callHello()
//'hello jay'