在main.ts(main.js)中添加
const app = createApp(App)
app.config.globalProperties.$http = () => {
alert(1111)
}
在组件中使用
import { defineComponent, reactive, ref,getCurrentInstance } from 'vue'
const _this:any = getCurrentInstance()
console.log(_this.appContext.config.globalProperties)
const { $http } = _this.appContext.config.globalProperties;
// 直接使用
$http()