换个思路:getCurrentInstance 只能在 setup 或生命周期钩子中调用。如果封装了一个 $http,app.config.globalProperties.$http = () => {}在setup 我们可以这样访问setup() { const internalInstance = getCurrentInstance() internalInstance.appContext.config.globalProperties.$http }在 route.ts 文件或者其他文件,直接使用导入的方式来访问import $http from 'http'; // $http.foo()
换个思路:
如果封装了一个 $http,
app.config.globalProperties.$http = () => {}
在setup 我们可以这样访问
在 route.ts 文件或者其他文件,直接使用导入的方式来访问