这个错误是因为getCurrentInstance不是全局可用的函数。它是Vue 3 Composition API中的一个函数,只能在setup函数内部使用。如果你想在全局范围内访问当前实例,可以使用provide和inject来实现。

你可以这样修改代码:

import { provide, inject } from 'vue'

const app = createApp({})

app.provide('proxy', proxy)

// 在其他组件中使用
const proxy = inject('proxy')

这样就可以在全局范围内访问proxy了。

setup const proxy = getCurrentInstance;报错了getCurrentInstance is not defined

原文地址: http://www.cveoy.top/t/topic/iskW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录