假设我们在main.js中定义了一个全局方法
//main.js
app.config.globalProperties.$hello = name => {
console.log('hello ' + name)
}
在其他页面中调用该方法
//other.js
import { getCurrentInstance } from "vue";
const { appContext } = getCurrentInstance();
const callHello = ()=>{
appContext.config.globalProperties.$hello('jay');
}
callHello()
//'hello jay'